21.) What is the diamond problem in the context of multiple inheritance in Java?
A) A collision between the names of instance variables
B) A conflict arising when multiple classes inherit from a common superclass
C) A situation where a method is overridden in multiple subclasses
D) A scenario where a class has two or more ambiguous paths to a common ancestor
22.) What is the purpose of the “super()” statement in a subclass constructor?
A) To call the constructor of the superclass
B) To call a static method in the superclass
C) To initialize the subclass’s attributes
D) To create a new instance of the superclass
23.) In Java, can you have a “final” method in a superclass that is overridden in a subclass?
A) Yes, and it can be further overridden in another subclass.
B) Yes, but it cannot be overridden in a subclass.
C) No, a “final” method cannot be overridden in any subclass.
D) Yes, but only if the subclass is in a different package.
24.) Which type of class relationship represents “has-a” relationship between classes?
A) Inheritance
B) Composition
C) Polymorphism
D) Aggregation
25.) What is the concept of method hiding in Java?
A) The process of encapsulating methods in a class
B) The process of dynamically selecting methods at runtime
C) The process of overriding a method in a subclass
D) The process of defining a static method with the same name in a subclass
26.) Can a subclass constructor invoke more than one constructor of its superclass in Java?
A) No, a subclass constructor can only invoke one constructor of its superclass.
B) Yes, a subclass constructor can invoke any number of constructors of its superclass.
C) Yes, but only if the superclass has a default constructor.
D) Yes, but only if the superclass is abstract.
27.) Which type of polymorphism is achieved through interfaces in Java?
A) Compile-time polymorphism
B) Run-time polymorphism
C) Static polymorphism
D) Interface polymorphism
28.) In Java, can a class be both abstract and final?
A) Yes, an abstract class can also be marked as final.
B) No, an abstract class cannot be marked as final.
C) Yes, but only if the class has no methods.
D) Yes, but only if the class has no attributes.
29.) What is the role of the “instanceof” operator in polymorphism?
A) To check if a class can be instantiated
B) To create a new instance of a class
C) To compare two objects for equality
D) To test if an object is of a specific type or interface
30.) What is the purpose of the “protected” access modifier in Java inheritance?
A) To make a method visible only within the class
B) To restrict method access to the same package
C) To allow access only to subclasses, regardless of package
D) To make a method globally accessible