Skip to content

Commit

Permalink
add polymorphism code
Browse files Browse the repository at this point in the history
  • Loading branch information
mdyasinahmed committed Sep 11, 2023
1 parent acd2fb0 commit b3344ff
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions oop_practice/src/main/java/Polymorphism/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package Polymorphism;

class Animal {
public void animalSound() {
System.out.println("An animal can make a sound.");
}
}

class Cow extends Animal {
public void animalSound() {
System.out.println("A cow says: Moooo");
}
}

class Cat extends Animal {
public void animalSound() {
System.out.println("A cat says: Meeooww");
}
}

class Main {
public static void main(String[] args) {
Animal myAnimal = new Animal();
Animal myCow = new Cow();
Animal myCat = new Cat();

myAnimal.animalSound();
myCow.animalSound();
myCat.animalSound();
}
}

0 comments on commit b3344ff

Please sign in to comment.