Consider the following class definition class father { protected : int age; public; father (int x) {age = x;} virtual void iam ( ) { cout < < I AM THE FATHER, my age is : << age<< end1:} }; Derive the two classes son and daughter from the above class and for each, define iam ( ) to write our similar but appropriate messages. You should also define suitable constructors for these classes. Now, write a main ( ) that creates objects of the three classes and then calls iam ( ) for them. Declare pointer to father. Successively, assign addresses of objects of the two derived classes to this pointer and in each case, call iam ( ) through the pointer to demonstrate polymorphism in action
Consider the following class definition class father { protected : int age; public; father (int x)
{age = x;} virtual void iam ( ) { cout < < I AM THE FATHER, my age is : << age<< end1:} }; Derive
the two classes son and daughter from the above class and for each, define iam ( ) to write our
similar but appropriate messages. You should also define suitable constructors for these
classes. Now, write a main ( ) that creates objects of the three classes and then calls iam ( ) for
them. Declare pointer to father. Successively, assign addresses of objects of the two derived
classes to this pointer and in each case, call iam ( ) through the pointer to demonstrate
polymorphism in action
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images