Difficulty: Easy
Correct Answer: None of the above statements is valid in Java.
Explanation:
Introduction / Context:
Java uses single inheritance for classes and multiple inheritance for interfaces. Understanding these rules is essential when designing class hierarchies and answering interview questions about extends and implements. This question checks which informal statement matches the real language rules.
Given Data / Assumptions:
Concept / Approach:
The correct rule is that a class may extend exactly one other class (except for java.lang.Object, which has no superclass) and may implement zero or more interfaces. It is perfectly legal for a class to both extend a superclass and implement several interfaces in a single declaration, such as:
class MyService extends BaseService implements Runnable, AutoCloseable
Any statement that contradicts these facts is invalid.
Step-by-Step Solution:
Verification / Alternative check:
Compiling a class like class Demo extends Object implements Runnable, AutoCloseable shows that the compiler accepts this pattern, which disproves options B, C, and E. Trying to compile a class that extends two different superclasses results in a compilation error, which disproves option A.
Why Other Options Are Wrong:
Common Pitfalls:
Many learners confuse Java with languages that allow full multiple inheritance for classes. Others mistakenly believe that implementing multiple interfaces is dangerous or not allowed. It is important to remember that Java chose single inheritance for classes to simplify the type system while still allowing flexible behavior composition through many interfaces.
Final Answer:
The correct choice is None of the above statements is valid in Java. because all the specific claims in the earlier options contradict the real inheritance and interface rules of the language.
Discussion & Comments