Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Classes, Objects, OOPs & Inheritance

Q30: Consider the following statements regarding Multiple Inheritance and Interfaces in Java:

1. Java officially permits multiple inheritance by allowing a single child class to simultaneously implement multiple different parent interfaces.
2. If a class implements two separate interfaces that both contain a 'default' method with the exact same signature, the Java compiler resolves the diamond problem by automatically prioritizing the interface listed first in the 'implements' clause.
3. To manually resolve a default method conflict during multiple inheritance, the developer must explicitly override the conflicting method in the child class and can invoke a specific parent's logic using the syntax InterfaceName.super.methodName().

Which of the above statements is/are correct?
A
Only 1 and 2
B
Only 1 and 3
C
Only 2 and 3
D
1, 2, and 3
✅ Correct Answer: B
🎯 Quick Answer:
The correct combination is 1 and 3. Statement 2 is incorrect because the Java compiler will never automatically guess which method to prioritize. Encountering identical default methods from two interfaces results in an immediate fatal compile-time error due to ambiguity.
Concept Definition: Multiple inheritance is the ability of a class to inherit behaviors from more than one parent.
While Java bans this for classes to prevent catastrophic architectural collisions (The Diamond Problem), it permits it for interfaces.
Structural Breakdown: A class achieves this via a comma-separated list: class Child implements ParentA, ParentB { }. Historical/Related Context: The Diamond Problem in C++ occurs when a class inherits from two parents that both define an identical method.
The runtime environment cannot determine which parent's memory to execute.
Java originally bypassed this completely because early interfaces only contained abstract methods (no bodies), meaning the child class provided the singular execution body anyway.
Causal Reasoning: When Java 8 introduced default methods (which have actual execution bodies), the Diamond Problem returned.
To maintain strict compiler safety, Java forces the programmer to resolve the conflict manually (Statement 3). By forcing the child class to explicitly override the method, the ambiguity is permanently eliminated.