Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Multithreading, Collections & I/O Streams

Q68: Consider the following statements regarding Default Methods in Interfaces:

1. The default keyword in Java 8 allows developers to inject fully implemented concrete methods into an interface without breaking the legacy codebase of classes already implementing that interface.
2. If a single class implements two distinct interfaces that both contain a default method with the exact same signature, the compiler throws an error, forcing the developer to manually override and resolve the conflict.
3. Default methods implicitly grant interfaces the ability to allocate Heap memory to hold state and instance variables, functionally merging their architectural role with Abstract Classes.

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: A
🎯 Quick Answer:
The correct combination is 1 and 2. Statement 3 is incorrect because interfaces in Java still mathematically cannot possess instance variables or hold mutable state. They only provide behavior. If state is required, developers must strictly utilize Abstract Classes.
Concept Definition: Default Methods (Defender Methods) enable the addition of new functionality to the interfaces of existing libraries, ensuring absolute backward compatibility with older versions of those interfaces.
Structural Breakdown: Syntax is public default void newMethod() { // implementation }. The implementing class can choose to use the default logic or override it with a specialized implementation.
Historical/Related Context: This feature was an absolute necessity for the release of Java 8. Oracle needed to add the stream() and forEach() methods to the supreme java.util.Collection interface.
Without the default keyword, every single company on Earth that had ever written a custom Collection class would instantly face compilation failures upon upgrading to Java 8 because they lacked the new method implementations.
Causal Reasoning: The compiler forces manual conflict resolution (Statement 2 context) to permanently solve the Multiple Inheritance "Diamond Problem." By forcing the implementing class to explicitly declare InterfaceA.super.methodName(), the JVM mathematically eliminates all runtime ambiguity regarding which specific behavior to execute.