Polymorphism is defined as the exhibition of a unique behavior or response by different objects when responding to the same message. Pointers to base class objects can also be used to point to derived class objects (although you cannot reference members in the derived class that are not in the base class when you use a base class pointer).
For example:
Teacher and Doctor classes derived from the base Professional class exhibits different behavior when a member function is called for one of their objects through a pointer or reference to the base Professional class. The Doctor class in our example assumes the existence of only one kind of doctor. In reality, a Professional class can employ doctors from various streams: cardiologist, dentist, eye specialist. Doctors can have different abilities and react differently in different situations. The company would recruit the number of doctors according to its requirements. For example, if there is a requirement of only one cardiologist, then the company would appoint only one cardiologist.
No comments:
Post a Comment