Question: Create a class Animal, with following specifications: Private variable name, you can use any default values. Private variable noOfLegs, you can use any default values.
Create a class Animal, with following specifications:
- Private variable name, you can use any default values.
- Private variable noOfLegs, you can use any default values.
- Public method Eat. Calling this prints out "Eating"
- Public method Talk. Calling this prints out "Talking"
- Getter/Setter for name
- Getter/Setter for noOfLegs
Create a class Dog, with following specifications:
- Extends from Animal Class
- Constructor which takes name as parameter and sets the name of the dog. Set the number of legs to 4
- Override method Eat. Calling this prints out "Eating Chimkin nuggets!"
- Override method Talk. Calling this prints out "Bark!!!"
Create a class Cow, with following specifications:
- Extends from Animal Class
- Constructor which takes name as parameter and sets the name of the cow. Set the number of legs to 4
-
- Override method Eat. Calling this prints out "Chewing grass"
- Override method Talk. Calling this prints out "Moo!!!"
Write a test program to test the classes.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
