0% found this document useful (0 votes)
22 views2 pages

PR 8

java practical 8 for mit adt unevercity inloni kalbhor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

PR 8

java practical 8 for mit adt unevercity inloni kalbhor
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment No.

NAME: RAVIRAJ SATISH KHARADE ROLL NO- 74

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.");
}

public void makeSound() {


System.out.println("The animal makes a sound.");
}
}

class Bird extends Animal {


@Override
public void move() {
System.out.println("The bird flies through the sky.");
}

@Override
public void makeSound() {
System.out.println("The bird chirps melodiously.");
}
}

class Panthera extends Animal {


@Override
public void move() {
System.out.println("The panthera stealthily walks on four legs.");
}

@Override
public void makeSound() {
System.out.println("The panthera roars fiercely.");
}
}
public class Main {
public static void main(String[] args) {

Animal bird = new Bird();


Animal panthera = new Panthera();

System.out.println("Bird:");
bird.move();
bird.makeSound();

System.out.println();

System.out.println("Panthera:");
panthera.move();
panthera.makeSound();
}
}

You might also like