Skip to main content
Lesson 29 - Inheritance, Polymorphism, and Abstract Classes
ZIPPDF (letter)
Lesson MenuPreviousNext
  
Inheritance page 3 of 8

  1. A key element in Object Oriented Programming is the ability to derive new classes from existing classes by adding new methods and redefining existing methods. The new class can inherit many of its attributes and behaviors from the existing class. This process of deriving new classes from existing classes is called inheritance, which we introduced in Lesson 14.



    The more general class that forms the basis for inheritance is called the superclass. The more specialized class that inherits from the superclass is called the subclass (or derived class).

  2. In Java, all classes belong to one big hierarchy derived from the most basic class, called Object. This class provides a few features common to all objects; more importantly, it makes sure that any object is an instance of the Object class, which is useful for implementing structures that can deal with any type of object. If we start a class from "scratch" the class automatically extends Object. For example:

    public class SeaCreature
    {
      ...
    }

    is equivalent to:

    public class SeaCreature extends Object
    {
      ...
    }

    when new classes are derived from SeaCreature, a class hierarchy is created. For example:

    public class Fish extends SeaCreature
    {
      ...
    }
    
    public class Mermaid extends SeaCreature
    {
      ...
    }

    This results in the hierarchy show below.


    Figure 28-1. SeaCreature and two derived classes


Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.