File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ package Interface ;
2+ interface Callback {
3+ void call (int person );
4+
5+ }
6+
7+ class Client implements Callback {
8+ public void call (int p ) {
9+ System .out .println ("Call p:" + p );
10+ }
11+
12+ void nonInterface () {
13+ System .out .println ("NonInterface method" );
14+ }
15+ }
16+
17+ class AnotherClient implements Callback {
18+ public void call (int p ) {
19+ System .out .println ("p*p=" + (p * p ));
20+ }
21+ }
22+
23+ public class Interface1 {
24+
25+ public static void main (String [] args ) {
26+ Callback c = new Client ();
27+ c .call (43 );
28+ // c.nonInterface(); will generate error as the reference variable is not class
29+ // type.
30+ Client ob = new Client ();
31+ ob .nonInterface ();
32+ AnotherClient obj = new AnotherClient ();
33+ c = obj ;
34+ c .call (9 );
35+
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments