-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.java
More file actions
36 lines (30 loc) · 746 Bytes
/
Interface.java
File metadata and controls
36 lines (30 loc) · 746 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
interface Animal {
void eat();
void sleep();
}
class Cat implements Animal{
public void eat(){
System.out.println("Cat eats fish");
}
public void sleep(){
System.out.println("Cat sleeps for 12 hours");
}
}
class Bear implements Animal{
public void eat(){
System.out.println("Bear eats honey");
}
public void sleep(){
System.out.println("Bear sleeps the entire winter");
}
}
public class Interface {
public static void main(String[] args) {
Animal animal1 = new Cat();
animal1.eat();
animal1.sleep();
System.out.println("====================================");
Animal animal2 = new Bear();
animal2.eat();
}
}