-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimplimentingInterfaces.java
More file actions
54 lines (37 loc) · 1.43 KB
/
implimentingInterfaces.java
File metadata and controls
54 lines (37 loc) · 1.43 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
import javax.swing.*;
interface Abc{
public void sayHello();
int ab =220;
}
interface Bcd {
int a =110;
// Static method in interfaces can have body and can be called from main using Interface_name.method_name();
public static void dontSayHello(){
System.out.println("I am not saying Hello");
}
}
public class implimentingInterfaces implements Abc, Bcd {
public void sayHello(){
System.out.println("Hello");
}
public static void dontSayHello(){
System.out.println("I am not going to say Hello");
}
public static void main(String[] args) {
Abc ab = new Abc() {
@Override
public void sayHello() {
System.out.println("I am saying Hello");
}
};
ab.sayHello(); // --> I am saying hello
Bcd.dontSayHello(); // --> I am not saying hello
implimentingInterfaces im = new implimentingInterfaces();
im.sayHello(); // --> Hello
im.dontSayHello(); // --> I am not going to say hello
System.out.println(Bcd.a); // --> 110 // Data members of an interface can be called can be directly called using their class name
System.out.println(Abc.ab); // --> 220 by Interface_name.data_member_name;
System.out.println(im.ab); // --> 220 // Can be called using both interface name as well as
System.out.println(im.a); // --> 110 // using object of the class
}
}