Skip to content

Commit f809aeb

Browse files
authored
Create inheritance&polymorphism.java
pls review it and merge it
1 parent 35b3144 commit f809aeb

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

inheritance&polymorphism.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Animal {
2+
void sound() {
3+
System.out.println("Animal makes a sound");
4+
}
5+
}
6+
7+
class Dog extends Animal {
8+
void sound() {
9+
System.out.println("Dog barks");
10+
}
11+
}
12+
13+
class Cat extends Animal {
14+
void sound() {
15+
System.out.println("Cat meows");
16+
}
17+
}
18+
19+
public class AnimalDemo {
20+
public static void main(String[] args) {
21+
Animal myDog = new Dog();
22+
Animal myCat = new Cat();
23+
24+
myDog.sound();
25+
myCat.sound();
26+
}
27+
}

0 commit comments

Comments
 (0)