0% found this document useful (0 votes)
4 views1 page

Java Dynamic Polymorphism Example

Write a java package to show dynamic polymorphism and interfaces.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Java Dynamic Polymorphism Example

Write a java package to show dynamic polymorphism and interfaces.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program-5

Aim: Write a java package to show dynamic polymorphism and interfaces.

Code:
package Java;

interface Animal {

void makeSound(); }

class Dog implements Animal {

@Override

public void makeSound() {

[Link]("Woof!"); } }

class Cat implements Animal {

@Override

public void makeSound() {

[Link]("Meow!"); } }

public class Main {

public static void main(String[] args) {

[Link]("Name - Ankit\n"+"Roll No. - 221901206");

Animal myAnimal = new Dog();

[Link]();

myAnimal = new Cat();

[Link](); }

Output:

You might also like