The syntax for defining a subclass class that inherits from another class is to add an extends clause in the class header:
The extends keyword specifies that the subclass inherits members of the superclass. That means that the subclass begins with a set of predefined methods and fields inherited from its hierarchy of superclasses.
JFrame allows us to create graphical applications. So we can use that to create our subclass of StatisticalDispersion and all of its inheriting subclasses.
Here, StatisticalDispersion is the subclass under JFrame. And it inherits from all the classes that JFrame inherits from, all the way back to the Object class.
The StatisticalDispersion Class Hierarchy
We are coding a class named StatisticalDispersion that extends the JFrame class, so we use the following header:
Because our StatisticalDispersion class extends JFrame, it inherits more than 300 methods and more than 30 fields. That’s because the JFrame class is a subclass of Frame, which is a subclass of Window, which is a subclass of Container, which is a subclass of Component, which is a subclass of Object.
A hierarchy is composed of subclasses which inherit methods and fields. Here, we make all of them available to the StatisticalDispersion class.
Subclasses do not necessarily need to use their inherited methods, but these are available if needed. The programmer does not need to write methods and define fields in classes which have already inherited them.
JFrame is the direct superclass of our StatisticalDispersion class. As you can see in the image, StatisticalDispersion refers to it. And as you can see in the code, JFrame follows the extends clause.
A class can have multiple direct subclasses but only one direct superclass. One can have many offspring but yet can only develop from one zygote.