Java Lambda Expressions MCQ - Multiple Choice Questions
Q. What is an access modifier in Java?
A. A keyword that specifies the access level of a class, method, or variableB. A keyword that specifies the data type of a variable
C. A keyword that specifies the return type of a method
D. A keyword that specifies the number of arguments in a method
Q. Which of the following is an access modifier in Java?
A. PublicB. Integer
C. Boolean
D. String
Q. Which access modifier restricts access to the same package and subclasses only?
A. PrivateB. Public
C. Protected
D. Default
Q. Which access modifier is the most restrictive in Java?
A. PrivateB. Protected
C. Public
D. Default
Q. Which access modifier allows access from any other class or package?
A. PrivateB. Protected
C. Public
D. Default
Q. Which access modifier is the default in Java if none is specified?
A. PrivateB. Protected
C. Public
D. Default
Q. Which access modifier allows access within the same class only?
A. PrivateB. Protected
C. Public
D. Default
Q. Which access modifier allows access within the same package?
A. PublicB. Private
C. Protected
D. Default
Q. What does the "protected" access modifier allow?
A. Access within the same class onlyB. Access within the same package only
C. Access from any other class or package
D. No access at all
Q. Which of the following is an example of a default access modifier in Java?
A. PrivateB. Public
C. Protected
D. Default
Q. What is the default access modifier for class members in Java?
A. publicB. private
C. protected
D. package-private
Q. Which of the following code snippets demonstrates the correct usage of the private access modifier in Java?
A.public class MyClass { private int number; public void setNumber(int num) { this.number = num; } public int getNumber() { return number; } }B.
public class MyClass { int number; private void setNumber(int num) { this.number = num; } private int getNumber() { return number; } }C.
public class MyClass { private int number; private void setNumber(int num) { this.number = num; } public int getNumber() { return number; } }D.
public class MyClass { int number; void setNumber(int num) { this.number = num; } void getNumber() { return number; } }