Skip to main content
Lesson 14 - Inheritance
Lesson MenuPreviousNext
  
Single Inheritance page 3 of 10

  1. Inheritance enables you to define a new class based on a class that already exists. The new class will inherit the characteristics of the existing class, but also provide some additional capabilities. This makes programming easier, because you can reuse and extend your previous work and avoid duplication of code.

  2. The class that is used as a basis for defining a new class is called a superclass (or parent class or base class). The new class based on the superclass is called a subclass (or child class or derived class.)

  3. The process by which a subclass inherits characteristics from just one parent class is called single inheritance. Some languages allow a derived class to inherit from more than one parent class in a process called multiple inheritance. Multiple inheritance, makes is difficult to determine which class will contribute what characteristics to the child class. Java avoids these issues by only providing support for single inheritance.

  4. The figure shows a superclass and a subclass. The line between them shows the "is a kind of" relationship. The picture can be read as "a Student is a kind of Person." The clouds represent the classes. That is, the picture does not show any particular Student or any particular Person, but shows that the class Student is a subclass of the Person class.

    Figure 14.1 - Subclass and Superclass.

  5. Inheritance is between classes, not between objects. A superclass is a blueprint that is followed when a new object is constructed. That newly constructed object is another blueprint that looks much like the original, but with added features. The subclass in turn can be used to construct objects that look like the superclass's objects, but with additional capabilities.

    Figure 14.2 - Subclass and Superclass.

  6. The figure shows a superclass and a subclass, and some objects that have been constructed from each. These objects that are shown as rectangles are actual instances of the class. In the picture, "Albert Einstein," "Lynne Brooke," and "Monty Vista" represent actual objects.


Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.