Exercise 1: Displaying Message Using Inheritance

This exercise requires you to implement the concepts of polymorphism/inheritance to display information about two base classes.

We'll cover the following

Problem Statement

The code below has:

  • A parent class named Animal.
    • Inside it define:
      • name
      • age
      • set_value(int a,string b) method:
        • takes age and name parameters and sets them to given values.
  • Then there are two base classes

    • Zebra
    • Dolphin
  • The base classes should

    • Return a string containing a message telling the age and the name as well as information about place of origin of that animal.
      • Here’s a link showing how you can add values to a string.
      • Hint: You have to create two separate message methods for both the base classes.

Example

Input:

  • name of Zebra is set to Ana and the age is set to 5
  • name of Dolphin is set to Jin and the age is set to 2

Then:

Get hands-on with 1400+ tech skills courses.