KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ParentInterfaceUsingChildInnerInterfaceLJH


1 /** @testcase PR#645 PUREJAVA Parent interface using public inner interface of child in same file */
2 interface Child extends Parent {
3     public interface Inner {
4         public String JavaDoc ok();
5     }
6 }
7
8 /** Parent must be in same file as child and be declared AFTER */
9 interface Parent {
10     public Child.Inner getChildInner();
11 }
12
13 public class ParentInterfaceUsingChildInnerInterfaceLJH {
14     public static void main (String JavaDoc[] args) {
15         Example me = new Example();
16         String JavaDoc result = me.getChildInner().ok();
17         if(!((result != null) && result.startsWith("ok")))
18           System.out.println("expected ok... got " + result);
19     }
20 }
21
22 class Example implements Parent {
23     public Child.Inner getChildInner() {
24         return new Child.Inner() {
25                 public String JavaDoc ok() {
26                     return "ok: " + getClass().getName();
27                 }
28             };
29     }
30 }
31
Popular Tags