-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathInterfaceUseDemo.java
More file actions
52 lines (47 loc) · 848 Bytes
/
InterfaceUseDemo.java
File metadata and controls
52 lines (47 loc) · 848 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
50
51
52
interface X
{
void print();
}
// SAM Interface
@FunctionalInterface
interface Z
{
void add(int x, int y);
//void sub(int x, int y);
}
class Y implements X
{
@Override
public void print(){
}
}
public class InterfaceUseDemo {
public static void main(String[] args) {
// 1. obj create
// 2. class create
// 3. interface implement
// 4. method override
// 5. Upcasting
X obj = new X(){
@Override
public void print(){
System.out.println("Print Call");
}
};
obj.print();
// 1. obj create
// 2. class create
// 3. interface implement
// 4. method override
// 5. Upcasting
X obj2=()->System.out.println("Print Call");
Z obj3 = (a,b)->{
System.out.println(a+b);
System.out.println(a+b);
System.out.println(a+b);
};
obj3.add(90,77);
/*Y obj = new Y();
obj.print();*/
}
}