Animal Inheritance
Implement the following class hierarchy, the inheritance access level should be public for all the descendent classes.
1. Add a protected data member named id of integer type to Animal class.
2. Add get/set methods for id data member in Animal class with public access.
3. Add a default constructor to each of the above created class. The constructor should initialize the id data member of Animal, Reptile, Bird and Mammal,to 0, 1, 2 and 3 respectively also it display a message “(class Name)’s default constructor”.
4. Add a parameterized constructor to each of the above created class. The constructor should initialize the id data member of Animal, Reptile, Bird and Mammal, to the specified id passed to the constructor as an argument ,also it display a message “(class Name)’s default constructor”. The parameterized constructor should call its base class parameterized constructor to initialize any data member inherited from the base class.
Comments
Leave a comment