We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 35b3144 commit f809aebCopy full SHA for f809aeb
inheritance&polymorphism.java
@@ -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
9
+ System.out.println("Dog barks");
10
11
12
13
+class Cat extends Animal {
14
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