To learn about inheritance
To understand how to inherit and override superclass methods
To be able to invoke superclass constructors
To learn about protected and package access control
To understand the common superclass
Object and how to override its
G To use inheritance for customizing user interfaces
In this chapter, we discuss the important concept of inheritance. Specialized classes can be created that inherit behavior from more general classes. You will learn how to implement inheritance in Java, and how to make use of the
Object class—the most general class in the inheritance hierarchy.
In the real world, you often categorize concepts into hierarchies. Hierarchies are frequently represented as trees, with the most general concepts at the root of the hierarchy and more specialized ones towards the branches. Figure 1 shows a typical example.
In Java it is equally common to group classes in inheritance hierarchies. The classes representing the most general concepts are near the root, more specialized classes towards the branches. For example, Figure 2 shows part of the hierarchy of Swing user-interface components in Java.
Sets of classes can form complex inheritance hierarchies.
We must introduce some more terminology for expressing the relationship between the classes in an inheritance hierarchy. The more general class is called the superclass. The more specialized class that inherits from the ...