Creating Subclasses

Creating Subclasses

For example,
suppose that we wanted to create a subclass named SubClass of another class named SuperClass. We would write:

class SubClass extends SuperClass
. . .

This declares that SubClass is the subclass of the Superclass class. It also implicitly declares that SuperClass is the superclass of SubClass. A subclass also inherits variables and methods from its superclass’s superclass, and so on up the inheritance tree.

A Java class can have only one direct superclass.
Java does not support multiple inheritance.

Creating a subclass can be as simple as including the extends clause in your class declaration.

Scroll to Top