Which statement is true about a class hierarchy in Java?

Prepare for the Object-Oriented Programming Test with flashcards and multiple choice questions. Each question comes with hints and explanations to enhance understanding. Master OOP concepts and succeed in your exam!

Multiple Choice

Which statement is true about a class hierarchy in Java?

Explanation:
In Java, a class can extend one superclass and implement multiple interfaces. This single inheritance for classes keeps the hierarchy simple, while implementing interfaces lets a class gain multiple sets of behaviors from different sources. So a class can inherit fields and methods from one parent class and, at the same time, promise to provide the methods defined by any number of interfaces it implements. This is why the statement describing extending one superclass and implementing multiple interfaces is accurate. The other ideas don’t fit Java’s rules: a class cannot extend more than one superclass, so multiple inheritance of classes is not allowed. An interface can extend another interface, not only be limited to its own definition. And a class can implement more than one interface, not just a single one. Put together, the allowed combination described—extending a single superclass while implementing multiple interfaces—best captures how Java handles class hierarchies.

In Java, a class can extend one superclass and implement multiple interfaces. This single inheritance for classes keeps the hierarchy simple, while implementing interfaces lets a class gain multiple sets of behaviors from different sources. So a class can inherit fields and methods from one parent class and, at the same time, promise to provide the methods defined by any number of interfaces it implements. This is why the statement describing extending one superclass and implementing multiple interfaces is accurate.

The other ideas don’t fit Java’s rules: a class cannot extend more than one superclass, so multiple inheritance of classes is not allowed. An interface can extend another interface, not only be limited to its own definition. And a class can implement more than one interface, not just a single one. Put together, the allowed combination described—extending a single superclass while implementing multiple interfaces—best captures how Java handles class hierarchies.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy