KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Test4


1 interface MyListener {
2     public void action();
3 }
4 public class Test4 {
5
6     public static void main (String JavaDoc [] args){
7         Test4 t4 = new Test4();
8         MyListener ml = t4.run();
9         ml.action();
10         MyListener ml2 = t4.runAgain();
11         ml2.action();
12     }
13
14     public MyListener run(){
15         class MyListener1 implements MyListener {
16             public void action(){
17                 System.out.println("Smile");
18             }
19         };
20         return new MyListener1();
21     }
22     
23     public MyListener runAgain(){
24         class MyListener2 implements MyListener {
25             public void action(){
26                 System.out.println("Smile 2");
27             }
28         };
29         return new MyListener2();
30     }
31 }
32
Popular Tags