3 public class InstanceOf3 {
4 static interface i1 { };
5 static interface i2 { };
6 static interface i3 extends i2 { };
7 static interface i4 extends i3 { };
8 static interface i5 { };
10 static class c2 extends c1 implements i1 { };
11 static class c3 extends c2 implements i4 { };
14 public static void main(String []args) {
16 checkInstance(x instanceof i1, "x", "i1");
17 checkInstance(x instanceof i2, "x", "i2");
18 checkInstance(x instanceof i3, "x", "i3");
19 checkInstance(x instanceof i4, "x", "i4");
20 checkInstance(x instanceof i5, "x", "i5");
21 checkInstance(x instanceof c1, "x", "c1");
22 checkInstance(x instanceof c2, "x", "c2");
23 checkInstance(x instanceof c3, "x", "c3");
24 checkInstance(x instanceof c4, "x", "c4");
25 checkInstance(x instanceof String, "x", "String");
26 checkInstance(x instanceof Integer, "x", "Integer");
27 checkInstance(x instanceof Object, "x", "Object");
30 public static void checkInstance(boolean cond, String obj, String classname) {
31 System.out.printf(obj);
33 System.out.printf(" is instance of ");
34 System.out.printf(classname);
35 System.out.printf(" :-)\n");
37 System.out.printf(" is *not* instance of ");
38 System.out.printf(classname);
39 System.out.printf(" :-(\n");