Inheritance: Base
Classes (Superclasses) and Derived Classes (Subclasses)
protected Members
Relationship between
Superclass Objects and Subclass Objects
Using Constructors and
Destructors in Subclasses
Inheritance
1. What is inheritance? What is the advantage of inheritance?
2. What is single inheritance? What is multiple inheritance?
3. What is a base class or superclass?
4. What is a derived class or subclass?
5. What is
protected access and what is its purpose?
Relationship between Superclass Objects
and Subclass Objects
1. How are superclass objects and subclass objects related?
2. When and how can references or pointers to superclass objects be
cast to references or pointers to subclass objects?
3. How can a subclass function use a superclass's data or functions?
4. How can the functions or methods of the superclass be overridden by
the subclass?
5. How are superclass constructors and finalizers invoked by subclass
constructors and destructors?
6. What is the difference between inheritance (is a) and composition (has a)?
Programming Exercise: Write an
inheritance hierarchy for class Quadrilateral, Trapezoid, Parallelogram,
Rectangle and Square. Use Quadrilateral as the base class of the
hierarchy. Make the hierarchy as deep (i.e., as many levels) as
possible. The private data of Quadrilateral should be the (x, y)
coordinate pairs for the four endpoints of the Quadrilateral. Write a
driver program that instantiates and displays objects of each of these
classes.