Module: | Classes, Objects, OOPs & Inheritance
Q29: Consider the following statements regarding the evolution of Java Interfaces:
1. Prior to Java 8, all methods declared within a Java interface were implicitly public and abstract, entirely lacking execution bodies.
2. Java 8 introduced 'default' methods in interfaces, allowing developers to add new implemented methods without breaking the existing codebase of classes that already implement the interface.
3. A class implementing an interface is legally permitted to override a 'static' method defined in that interface using the @Override annotation to provide a custom implementation.
Which of the above statements is/are correct?
2. Java 8 introduced 'default' methods in interfaces, allowing developers to add new implemented methods without breaking the existing codebase of classes that already implement the interface.
3. A class implementing an interface is legally permitted to override a 'static' method defined in that interface using the @Override annotation to provide a custom implementation.
Which of the above statements is/are correct?
✅ Correct Answer: A
🎯 Quick Answer:
The correct combination is 1 and 2. Statement 3 is incorrect because static methods in an interface belong strictly to the interface itself (accessed via InterfaceName.methodName()). They are not inherited by implementing classes and therefore mathematically cannot be overridden.A class that implements the interface signs a contract agreeing to define specific methods.
Structural Breakdown: In modern Java (8+), an interface can contain: implicit public static final constant variables, abstract methods, default methods (with bodies), static methods (with bodies), and (since Java 9) private methods.
Historical/Related Context: The introduction of 'default' methods in Java 8 was an architectural necessity.
Oracle needed to add new methods (like the forEach method) to the foundational java.util.Collection interface to support Lambda expressions.
Without default methods, adding forEach would have instantly broken millions of legacy enterprise applications that implemented Collection, as they would suddenly be missing a required method implementation.
Causal Reasoning: Default methods provide backward compatibility.
If an older class does not provide a custom implementation for the newly added default method, it simply falls back to safely executing the default body provided securely within the interface itself.