-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tutorial16_Interface.java
52 lines (45 loc) · 1.29 KB
/
Tutorial16_Interface.java
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
// An interface has default public methods and data //
// No public methods can have a body //
// We can have private and default (with default modifier) methods having bodies //
// We can only have default public data and they are final //
// A class can implement multiple interfaces //
// interface can also be extended by other interfaces //
// multiple inheritance in interfaces are allowed //
interface IF1{
int a = 12; // by default public
private void method1(){
System.out.println("Method 1 in IF1 called from Method 2 in IF1!");
}
default void method2(){
method1();
}
void method3();
};
interface IF2{
void method4();
};
interface IF3 extends IF1, IF2{
void method6();
}
class Class1{
public void method5(){
System.out.println("Method 5 in Class1!");
}
};
class Base1 extends Class1 implements IF1, IF2{
public void method3(){
System.out.println("Method 2 in Base1!");
}
public void method4(){
System.out.println("Method 4 in Base1!");
}
};
public class Tutorial16_Interface {
public static void main(String[] args) {
Base1 obj = new Base1();
obj.method2();
obj.method3();
obj.method4();
obj.method5();
}
}