PR 8
PR 8
Title:- Write a Java program to create a base class Animal with methods move() and makeSound(). Create
two subclasses Bird and Panthera. Override the move() method in each subclass to describe how each
animal moves. Also, override the makeSound() method in each subclass to make a specific sound for each
animal.(POLYMORPHISM )
Source Code:
class Animal {
public void move() {
System.out.println("The animal moves in some way.");
}
@Override
public void makeSound() {
System.out.println("The bird chirps melodiously.");
}
}
@Override
public void makeSound() {
System.out.println("The panthera roars fiercely.");
}
}
public class Main {
public static void main(String[] args) {
System.out.println("Bird:");
bird.move();
bird.makeSound();
System.out.println();
System.out.println("Panthera:");
panthera.move();
panthera.makeSound();
}
}