Documentation
1. Animal Class
Type
Abstract Class
Purpose
Represents a generic animal with basic attributes and behavior.
Attributes
- name (String): Name of the animal.
- age (int): Age of the animal.
Methods
- getName(): Returns the name of the animal.
- getAge(): Returns the age of the animal.
- makeSound(): Abstract method. Each subclass defines its own sound.
2. Pet Interface
Type
Interface
Purpose
Represents a pet that can perform actions like playing.
Methods
- play(): Defines how a pet plays. Implemented by classes like Dog and Cat.
3. Dog Class
Type
Class
Inheritance
Extends Animal and implements Pet
Purpose
Represents a dog with breed and specific behaviors.
Attributes
- breed (String): The breed of the dog.
Methods
- displayBreed(): Prints the breed of the dog.
- makeSound(): Prints the dog's sound ("Woof! Woof!").
- play(): Prints that the dog is playing.
4. Cat Class
Type
Class
Inheritance
Extends Animal and implements Pet
Purpose
Represents a cat with color and specific behaviors.
Attributes
- color (String): The color of the cat.
Methods
- displayColor(): Prints the color of the cat.
- makeSound(): Prints the cat's sound ("Meow! Meow!").
- play(): Prints that the cat is playing.
5. AnimalTest Class
Type
Class
Purpose
Tests the functionality of Animal, Dog, and Cat classes.
Details
- Creates an array of Animal objects.
- Demonstrates polymorphism: each animal makes its sound using
makeSound().
- Calls play() method from Pet interface using type casting.
End of Documentation