21.) What is a class in Java?
A) An instance of an object
B) A template for creating objects
C) A predefined method in Java
D) A data type for variables
22.) Which keyword is used to create an instance of a class in Java?
A) new
B) this
C) class
D) object
23.) What is an object reference in Java?
A) The memory address of an object
B) The name of a class
C) A keyword for creating objects
D) A variable that holds the memory location of an object
24.) Which of the following is a valid way to access an instance variable of an object in Java?
A) ClassName.variableName
B) objectName.variableName
C) variableName.objectName
D) variableName.ClassName
25.) What is the “constructor” of a class in Java?
A) A method used for destroying objects
B) A reserved keyword indicating class creation
C) A method used to initialize objects
D) A method used for inheritance
26.) Which of the following is true about the default constructor in Java?
A) It takes parameters and initializes object attributes.
B) It is provided by the compiler if no constructor is defined.
C) It is used to destroy objects.
D) It can be overloaded with multiple constructors.
27.) What is the relationship between a method and an object in Java?
A) A method is an object.
B) An object is a method.
C) A method operates on an object’s data and behavior.
D) A method creates objects.
28.) In Java, can a class have multiple methods with the same name but different parameters?
A) Yes, but it is discouraged.
B) No, it will result in a compilation error.
C) Yes, and it is called method overloading.
D) No, it violates encapsulation principles.
29.) What is the purpose of the “static” keyword in Java class members (fields and methods)?
A) It indicates that the member is dynamically allocated.
B) It signifies that the member belongs to the object.
C) It indicates that the member is shared among all instances of the class.
D) It is used to override methods.
30.) What is the access modifier used to specify that a class member can be accessed by any class in the same package?
A) private
B) protected
C) protected
D) default (package-private)
Related