Define a base class called animal with following members:
a. string type data member to store the name of the animal
b . integer member to store the age of animal in years
c. method to display the age and name of the animal
Derive to classes named Cat and Dog from animal class then write a driver program to create Cat and Dog objects with suitable values. Display the contents of objects by calling the display method on the derived objects
Loading
Pranay RanaPosted Jan 28, 2014, 11:00 AM
{
public string Name {get; set;}
public string Age {get; set;}
{
return "Name" : Name + " Age:" + Age;
}
}
public class Cat : Animal{}
public class Dog : Animal{}
public class Client
{
public Client()
{
Animal a = new Cat();
a.Age=10; a.Name="A";
a.ToString();
Animal b = new Dog();
b.Age=10; b.Name="A";
b.ToString();
}
}