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
andname
parameters and sets them to given values.
- takes
- Inside it define:
-
Then there are two base classes
Zebra
Dolphin
-
The base classes should
- Return a string containing a message telling the
age
and thename
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.
- Return a string containing a message telling the
Example
Input:
name
ofZebra
is set to Ana and theage
is set to 5name
ofDolphin
is set to Jin and theage
is set to 2
Then:
Get hands-on with 1400+ tech skills courses.