31.) In Java, can an abstract class have instance variables?
A) No, abstract classes cannot have instance variables.
B) Yes, but only if the instance variables are declared as “static.”
C) Yes, abstract classes can have both instance and static variables.
D) Yes, but only if the abstract class has no methods.
32.) Which type of inheritance is implemented by interfaces in Java?
A) Single inheritance
B) Multiple inheritance
C) Hierarchical inheritance
D) Hybrid inheritance
33.) What is the “final” keyword used for in the context of classes and methods in Java?
A) To indicate that a class cannot be instantiated
B) To indicate that a method cannot be overridden
C) To make a method accessible only within the class
D) To specify the order of method invocation
34.) In Java, can an abstract class have a constructor?
A) No, abstract classes cannot have constructors.
B) Yes, but only if the constructor is private.
C) Yes, abstract classes can have both default and parameterized constructors.
D) Yes, but only if the abstract class has no attributes.
35.) Can an abstract class implement an interface in Java?
A) No, abstract classes cannot implement interfaces.
B) Yes, but only if the interface is also abstract.
C) Yes, abstract classes can implement interfaces regardless of whether the interface is abstract or not.
D) Yes, but only if the interface has a single method.
36.) What is dynamic method dispatch in Java polymorphism?
A) The process of calling static methods at runtime
B) The process of selecting the appropriate method based on the object’s type at runtime
C) The process of method overloading
D) The process of method hiding
37.) What is the purpose of the “superclass reference variable” in Java polymorphism?
A) To reference a subclass object from a superclass reference
B) To reference a superclass object from a subclass reference
C) To store the superclass’s attributes in a subclass
D) To access private members of the superclass
38.) In Java, can a method be both “final” and “static”?
A) Yes, it is a common practice.
B) No, it is not allowed.
C) Yes, but only if the method is private.
D) Yes, but only if the method is public.
39.) What is the purpose of the “abstract” keyword in method declaration within an interface in Java?
A) To indicate that the method can have different implementations
B) To indicate that the method is private and cannot be accessed
C) To indicate that the method has a default implementation
D) To indicate that the method has no implementation and must be overridden
40.) What is method resolution order (MRO) in Java multiple inheritance?
A) The order in which methods are declared in a class
B) The order in which methods are invoked by the compiler
C) The order in which methods are overridden in subclasses
D) The order in which methods are searched and selected during inheritance