The Power of Inheritance
You have used inheritance every time you worked with one of the standard Java classes such as String
or Integer
. Java classes are organized into a pyramid-shaped hierarchy of classes in which all classes descend from the Object
class.
A class of objects inherits from all superclasses that are above it. To get a working idea of how this operates, consider the JApplet
class. This class is a superclass of all applets, browser-based Java programs that use a graphical user interface framework called Swing. The JApplet
class is a subclass of Applet
.
A partial family tree of JApplet
is shown in Figure 12.1. Each of the boxes is a class, and the lines connect a superclass to any subclasses below it.
Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.