Polymorphism
Inheritance and Polymorphism
- Inheritance allows us to define a family of classes that have
common data and behaviors.
- Polymorphism is the ability to manipulate objects of these classes in a
type-independent way.
- In C++, polymorphism is supported only when we use
pointers (or references) to objects.
- The particular method to invoke on an object is not determined until
run-time and is based on the specific type of object actually addressed.
Inheritance and Pointers
- A base class pointer can point to an object of a derived class type.
- The derived class object is a base class object.
- But we can't use the pointer to call methods only defined in the
derived class.
- A derived class pointer cannot point to an object of a base class type.
The base class doesn't have any of the extensions provided by the
derived class.
Last Modified: Monday, 28-Aug-2006 10:16:04 EDT