Difficulty: Easy
Correct Answer: Multiple inheritance of classes
Explanation:
Introduction / Context:
Java is an object oriented language that supports inheritance, but it deliberately restricts some forms of inheritance to simplify the language and avoid ambiguity. This question checks whether you know which kind of inheritance Java does not support directly through classes and how developers work around that limitation.
Given Data / Assumptions:
Concept / Approach:
Single inheritance means each class has at most one direct superclass. Multilevel inheritance means a chain of inheritance where a class extends another class that itself extends yet another class. Hierarchical inheritance means multiple subclasses share the same superclass. Java supports all of these patterns using normal class extends relationships. Multiple inheritance of classes, however, means that a single class would extend two or more direct superclasses, which Java forbids. The designers removed this feature to avoid the diamond problem and similar ambiguities, and instead introduced interfaces as a way to achieve multiple inheritance of type without multiple inheritance of implementation.
Step-by-Step Solution:
Step 1: Consider single inheritance: class B extends A is allowed in Java and is used everywhere.Step 2: Consider multilevel inheritance: class C extends B and class B extends A is also allowed, forming a chain A to B to C.Step 3: Consider hierarchical inheritance: multiple classes such as B and C both extend A, sharing A as a common parent, which is also allowed.Step 4: Multiple inheritance of classes would require syntax like class D extends B, C which Java does not allow, because a class cannot extend more than one class directly.Step 5: Therefore multiple inheritance of classes is not supported directly, making option B the correct answer.
Verification / Alternative check:
If you try to compile a Java class declaration with two superclasses, the compiler reports an error stating that a class cannot extend multiple classes. In contrast, you can write class D extends B implements X, Y; which shows that Java supports a combination of single class inheritance and multiple interface implementation. This behaviour confirms that multiple inheritance of classes is the unsupported pattern here.
Why Other Options Are Wrong:
Option A, multilevel inheritance, is supported as long as you have a chain of extends relationships. Option C, single inheritance, is the core inheritance model in Java. Option D, hierarchical inheritance, is also permitted because many subclasses can extend the same superclass. These patterns are common in Java frameworks and standard library classes.
Common Pitfalls:
A frequent misunderstanding is thinking that Java has no multiple inheritance at all, when in fact it supports multiple inheritance of type through interfaces. Another pitfall is trying to simulate multiple inheritance of classes by deep inheritance chains instead of using composition or delegation. Good object oriented design in Java often uses interfaces, composition, and design patterns such as adapter or decorator to model behaviours that in other languages might use multiple class inheritance.
Final Answer:
Java does not support multiple inheritance of classes directly; a class cannot extend more than one superclass.
Discussion & Comments