-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface2.java
More file actions
62 lines (54 loc) · 1.18 KB
/
Interface2.java
File metadata and controls
62 lines (54 loc) · 1.18 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
54
55
56
57
58
59
60
61
62
/*
* Interface supports multiple interfaces
*
* class - interface -> implements
* interface - interface -> extends
* class - class -> extends
*/
public class Interface2 {
public static void main(String[] args){
A obj1 = new Human();
// obj1.sleep(); //We can only access methods in A interface;
obj1.eat();
//To access both methods in human we have to implement reference variable using Human class
Human human = new Human();
human.eat();
human.sleep();
human.run();
C obj2 = new Alien();
// obj2.trex();
obj2.dtx();
}
}
interface A{
void eat();
void run();
}
interface B{
void sleep();
}
class Human implements A,B{ //We can use multiple interfaces
public void sleep(){
System.out.println("Sleeping");
}
public void eat(){
System.out.println("Eating");
}
public void run(){
System.out.println("Running");
}
}
interface C{
void dtx();
}
interface D extends C{
void trex();
}
class Alien implements D{
public void dtx(){
System.out.println("dtx");
}
public void trex(){
System.out.println("trex");
}
}