🎯 Objective
To understand and implement Java inheritance by creating a class hierarchy for animals in a zoo.
Part 1: Base Class Creation
Task: Create a base class
Animal
.Include common attributes (e.g., name, age).
Implement methods like
eat()
,sleep()
.
Part 2: Creating Subclasses
Task: Create at least three subclasses of
Animal
(e.g.,Lion
,Elephant
,Monkey
).Each subclass should have unique attributes or behaviors - this is your choice, you must include at least one.
Demonstrate the use of
super
to access superclass methods and constructors.
Part 4: Overriding Methods
Task: Override methods in the subclasses.
Example: Overriding the
eat()
method to reflect each animal's specific diet.
Part 5: Implementing a displayInfo()
Method
Task: Implement a
displayInfo()
method in each class to print details about each animal.
Part 6: Main Class and Testing
Task: Create a
ZooTest
class to instantiate different animals and call their methods.Demonstrate polymorphism by storing different animals in an
Animal
ArrayList and iterating through it to calldisplayInfo()
.
!🚚 Deliverables
Upload the following files in a zip folder that you have created:
...