-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
49 lines (42 loc) · 937 Bytes
/
Copy pathMain.java
File metadata and controls
49 lines (42 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package Abstraction;
abstract class Animal{
abstract void walk();
abstract void sleep();
Animal(){
System.out.println("Animal is created");
}
public void eat(){
System.out.println("Animal is eating");
}
}
class Horse extends Animal{
Horse(){
System.out.println("Horse is created");
}
@Override
void walk(){
System.out.println("Horse walks on 4 legs");
}
@Override
void sleep() {
System.out.println("Horse sleeps while standing");
}
}
class Chicken extends Animal{
@Override
void walk() {
System.out.println("Chicken walks on 2 legs");
}
@Override
void sleep() {
System.out.println("Chicken sleeps while sitting");
}
}
public class Main {
public static void main(String[] args) {
Horse horse = new Horse();
horse.walk();
horse.sleep();
horse.eat();
}
}