Java keeps class inheritance simple: each class can extend one superclass, yet implement several interfaces. This lets it inherit shared fields and methods while taking on different behaviors—a bit like one family tree with several skill sets. Interfaces can also extend other interfaces.

Multiple Choice

Which statement is true about a class hierarchy in Java?

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.

A Java class can extend one superclass and implement several interfaces. That simple rule shapes how Java programs organize shared code and describe behavior. A class gets its inherited fields and methods from one parent class, then can agree to meet the requirements of many interfaces. The result is a hierarchy with a clear family tree, plus room for a class to take on different roles.

This design may seem restrictive at first. Why not let a class inherit from several parent classes? Java’s answer is to keep class inheritance predictable while using interfaces to support flexible behavior. Once the distinction between the two is clear, Java’s class hierarchy becomes much easier to read.

One parent class, several possible roles

A superclass is a class that another class extends. The child class, also called a subclass, inherits accessible members from that parent and can add its own fields and methods. It may also override certain inherited methods to give them behavior suited to the child.

For example, a basic Vehicle class could hold details and behavior shared by cars, buses, and bicycles:


class Vehicle {

void start() {

System.out.println("The vehicle is starting.");

}

}

class Car extends Vehicle {

void openTrunk() {

System.out.println("The trunk is open.");

}

}

Here, Car extends Vehicle. A Car object can use the inherited start() method and its own openTrunk() method. The relationship is easy to describe: a car is a kind of vehicle.

Java allows a class to extend only one class. So Car could not also extend a separate EnginePowered class. That restriction avoids ambiguity when two parent classes define the same method or field. If both parents had a start() method, for instance, the language would need a clear rule for deciding which version the child inherits. Single inheritance sidesteps that particular tangle.

It also encourages class trees to stay focused. A superclass should represent a genuine shared “is a” relationship, not simply serve as a convenient place to collect unrelated code. If a class seems to need several parents, interfaces may be a better fit.

Interfaces describe what a class can do

An interface sets out a contract. It names methods that a class must provide, while leaving the class free to decide how those methods work. A class can implement multiple interfaces, which lets it take on several roles without inheriting from several parent classes.

Consider a system that tracks objects that can be saved and displayed:


interface Savable {

void save();

}

interface Displayable {

void display();

}

class Photo implements Savable, Displayable {

public void save() {

System.out.println("Saving the photo.");

}

public void display() {

System.out.println("Showing the photo.");

}

}

Photo implements both Savable and Displayable. It must provide the methods required by those interfaces, so the class makes two promises: it can be saved, and it can be displayed. Neither interface needs to be a superclass, and the class does not inherit a second set of class fields or parent-class behavior.

That difference matters. A Photo might share implementation with one superclass—perhaps MediaItem—while also meeting the contracts of Savable, Displayable, and Shareable. Its class declaration could look like this:


class Photo extends MediaItem

implements Savable, Displayable, Shareable {

// Required methods and other class details

}

The order is part of Java’s syntax: extends comes before implements. There can be one superclass after extends, followed by any number of interfaces after implements.

Interfaces can extend interfaces, too

Interfaces are not limited to standing alone. One interface can extend another interface, building on its contract. For example:


interface Printable {

void print();

}

interface ColorPrintable extends Printable {

void chooseColor();

}

A class that implements ColorPrintable must provide both chooseColor() and print(). The second interface carries the requirement inherited from the first, along with its own method.

An interface can also extend more than one interface. That gives interfaces a way to combine related contracts:


interface Printable {

void print();

}

interface Shareable {

void share();

}

interface PublicReport extends Printable, Shareable {

void showSummary();

}

Any class that implements PublicReport must meet the requirements from all three interfaces: printing, sharing, and showing a summary. So Java rules out multiple inheritance for classes, but permits an interface to inherit from multiple interfaces. Those are different relationships with different purposes.

A hierarchy is more than a family tree

It helps to think of a superclass as a family relationship and an interface as a capability or role. A Bus may extend Vehicle because a bus is a vehicle. It might implement PublicTransport because it provides public transport, and Trackable because its location can be followed.

This distinction keeps designs expressive. Many unrelated classes can implement the same interface. A bus, a delivery van, and a bike-share bicycle might all implement Trackable, even if they do not share a useful superclass beyond a broad base type. Code can then work with the interface rather than needing to know the exact class:


void locate(Trackable item) {

item.updateLocation();

}

The method only needs an object that can fulfill the Trackable contract. It does not need to know whether that object is a bus or a bicycle. This is one reason interfaces are central to polymorphism: different kinds of objects can respond to the same method call in their own ways.

Java interfaces can include more than abstract method declarations. Modern Java also allows interfaces to define default methods and static methods, among other features. A default method supplies an implementation that classes may use or override. Even so, an interface is not simply another class in disguise. It remains a way to define a contract and, in some cases, offer shared behavior without creating a second superclass.

Why Java draws the line

Multiple class inheritance can create the “diamond problem.” Imagine two parent classes that both inherit from the same base class, and a child class inherits from both parents. Which inherited version should the child use if the two parents provide competing implementations? What happens if each parent has its own copy of a field from the shared base?

There are ways programming languages can handle such conflicts, but they add rules that developers must learn and apply. Java’s approach keeps class inheritance simpler: one direct superclass. Interfaces then provide a way to express multiple capabilities, with the class itself supplying the required implementations or resolving any relevant conflicts.

This is not a claim that interfaces solve every design problem. A long list of interfaces can make a class hard to understand, just as an overly deep class hierarchy can become brittle. Good structure comes from giving each type a clear purpose. Use a superclass when there is a meaningful shared base and inherited implementation. Use interfaces when different classes should promise the same behavior, even if they are otherwise unrelated.

The shape of Java inheritance

Java’s rules can be summed up in a few lines:

  • A class extends one superclass at most.

  • A class may implement multiple interfaces.

  • An interface may extend one or more interfaces.

  • A class can inherit implementation from its superclass while fulfilling contracts from its interfaces.

That combination gives Java both a firm structure and useful flexibility. The class hierarchy provides a straightforward inheritance path, while interfaces let objects participate in several roles at once. In a well-designed program, those two tools work together: one parent class for shared foundations, and as many relevant contracts as the class genuinely needs.