Question: c++ implement using inheritance and polymorphism Exercise 1: For the first part of this lab, we are going to see if base class pointers can

c++
implement using
inheritance and polymorphism  c++ implement using inheritance and polymorphism Exercise 1: For the first
part of this lab, we are going to see if base class
pointers can point to an object of derived class and vice versa.
Perform the following steps Create a class called Animal. Message is data

Exercise 1: For the first part of this lab, we are going to see if base class pointers can point to an object of derived class and vice versa. Perform the following steps Create a class called Animal. Message is data member in Animal class. An animal can speak so create a public method named speak in the which returns a "Message" Modify the definition of the speak method so that it returns the string "speak() called." A Dog is an Animal. Create a class named Dog. Use public inheritance. The Dog class will inherit the speak method from Animal. Override this method in the Dog class so that it returns "woof!" when called. Add the following lines in the main function of your program, note the output. Animal objAnimal; Dog objDog; Animal *ptrAnimal = lobjAnimal: Dog *ptrDog - &objDog; cout speak() speak() speak() speak ()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!