-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain1.java
More file actions
53 lines (45 loc) · 1.02 KB
/
Copy pathMain1.java
File metadata and controls
53 lines (45 loc) · 1.02 KB
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
50
51
52
53
package Abstraction;
interface Animal{
abstract void walk();
abstract void sleep();
public void eat();
}
class Horse implements Animal{
Horse(){
System.out.println("Horse is created");
}
@Override
public void walk(){
System.out.println("Horse walks on 4 legs");
}
@Override
public void sleep() {
System.out.println("Horse sleeps while standing");
}
@Override
public void eat() {
System.out.println("Horse is always eating");
}
}
class Chicken implements Animal{
@Override
public void walk() {
System.out.println("Chicken walks on 2 legs");
}
@Override
public void sleep() {
System.out.println("Chicken sleeps while sitting");
}
@Override
public void eat() {
System.out.println("Chicken is always eating.");
}
}
public class Main1 {
public static void main(String[] args) {
Horse horse = new Horse();
horse.walk();
horse.sleep();
horse.eat();
}
}