-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaces_02.java
More file actions
52 lines (38 loc) · 1.11 KB
/
Interfaces_02.java
File metadata and controls
52 lines (38 loc) · 1.11 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
// a class can implement multiple interfaces
// here is an example
interface A {
// every variable in interface are by default final and static
int age = 44;
String area = "something";// final and static we can directly use interface variables
void show();
void config();
}
interface X {
void run();
}
// can interface extend another interface how do we do that
interface Y extends X {
}
class B implements A, X {
public void config() {
System.out.println("in show");
}
public void show() {
System.out.println("in config");
}
public void run() {
System.out.println("x is running...");
}
}
public class Interfaces_02 {
public static void main(String[] args) {
A obj = new B();
obj.show();
obj.config();
// obj.run();// this will not work because we are creating refrence of a and a
// has no idea what run method is // so take care of it
X obj1 = new B();
obj1.run();
// obj1.config() // x has no idea what config is
}
}