gs gs128 Java Classes Methods - Java Access Control - Quiz No.1
gs gs128 Java Quiz
This quiz belongs to book/course code gs gs128 Java of gs organization. We have 136 quizzes available related to the book/course Java. This quiz has a total of 19 multiple choice questions (MCQs) to prepare and belongs to topic Java Classes Methods. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
Question 1: Which of these access specifiers must be used for main() method?
private
public
protected
none of the mentioned
Question 2: Which of these is used to access a member of class before object of that class is created?
public
private
static
protected
Question 3: Which of these is used as a default for a member of a class if no access specifier is used for it?
private
public
public, within its own package
protected
Question 4: What is the process by which we can control what parts of a program can access the members of a class?
Polymorphism
Abstraction
Encapsulation
Recursion
Question 5: Which of the following statements are incorrect?
public members of class can be accessed by any code in the program
private members of class can only be accessed by other members of the class
private members of class can be inherited by a subclass, and become protected members in subclass
protected members of a class can be inherited by a subclass, and become private members of the subclass
Question 6: What will be the output of the following Java code?
class access { public int x; private int y; void cal(int a, int b) { x = a + 1; y = b; } } public class access_specifier { public static void main(String args[]) { access obj = new access(); obj.cal(2, 3); System.out.println(obj.x + " " + obj.y); } }
3 3
2 3
Runtime Error
Compilation Error
Question 7: What will be the output of the following Java code?
class access { public int x; private int y; void cal(int a, int b) { x = a + 1; y = b; } void print() { System.out.println(" " + y); } } public class access_specifier { public static void main(String args[]) { access obj = new access(); obj.cal(2, 3); System.out.println(obj.x); obj.print(); } }
2 3
3 3
Runtime Error
Compilation Error
Question 9: Which of these access specifier must be used for class so that it can be inherited by another subclass?
public
private
protected
none of the mentioned
Question 10: Which one of the following is not an access modifier?
Public
Private
Protected
Void
Question 11: All the variables of class should be ideally declared as?
private
public
protected
default
Question 12: Which of the following modifier means a particular variable cannot be accessed within the package?
private
public
protected
default
Question 13: How can a protected modifier be accessed?
accessible only within the class
accessible only within package
accessible within package and outside the package but through inheritance only
accessible by all
Question 14: What happens if constructor of class A is made private?
Any class can instantiate objects of class A
Objects of class A can be instantiated only within the class where it is declared
Inherited class can instantiate objects of class A
classes within the same package as class A can instantiate objects of class A
Question 15: All the variables of interface should be?
default and final
default and static
public, static and final
protect, static and final
Question 16: What is true of final class?
Final class cause compilation failure
Final class cannot be instantiated
Final class cause runtime failure
Final class cannot be inherited
Question 19: Which is the modifier when there is none mentioned explicitly?
protected
private
public
default