Question: Write the following program in java: Create Classes: Mammal, Reptile, Bird Each class has two instances variables -- name (String) and legs (int) Create constructor(s)

Write the following program in java:

  • Create Classes: Mammal, Reptile, Bird
  • Each class has two instances variables -- name (String) and legs (int)
  • Create constructor(s) to initialize the object.
  • Each class has two methods:
     String info() { return "I am " + name + ", I have " + legs + " legs". } void say() { System.out.println(info()); } 
  • Create a driver class and provide main() method.
  • In main(), create 10 objects of Mammal, Reptile, and Bird in random order, then use a loop to display .say() of each object.
  • Apply subtype polymorphism solution with abstract class.

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!