forked from disha2sinha/Object-Oriented-Programming-in-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInterface1.java
37 lines (30 loc) · 821 Bytes
/
Interface1.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
package Interface;
interface Callback {
void call(int person);
}
class Client implements Callback {
public void call(int p) {
System.out.println("Call p:" + p);
}
void nonInterface() {
System.out.println("NonInterface method");
}
}
class AnotherClient implements Callback {
public void call(int p) {
System.out.println("p*p=" + (p * p));
}
}
public class Interface1 {
public static void main(String[] args) {
Callback c = new Client();
c.call(43);
// c.nonInterface(); will generate error as the reference variable is not class
// type.
Client ob = new Client();
ob.nonInterface();
AnotherClient obj = new AnotherClient();
c = obj;
c.call(9);
}
}