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 { };
9 static interface i6 extends i3 { };
10 static interface i7 extends i4, i6 { };
11 static interface i8 extends i2, i7 { };
13 static class c2 extends c1 implements i1 { };
14 static class c3 extends c2 implements i4 { };
17 public static void main(String []args) {
24 checkInstance(x instanceof c1, "x", "c1");
25 checkInstance(x instanceof c2, "x", "c2");
26 checkInstance(x instanceof c3, "x", "c3");
27 checkInstance(x instanceof c4, "x", "c4");
28 checkInstance(x instanceof String, "x", "String");
29 checkInstance(x instanceof Integer, "x", "Integer");
31 checkInterfaces(x, "x");
32 checkInterfaces(y, "y");
33 checkInterfaces(z, "z");
34 checkInterfaces(u, "u");
35 checkInterfaces(v, "v");
38 public static void checkInterfaces(Object y, String name) {
39 checkInstance(y instanceof Object, name, "Object");
40 checkInstance(y instanceof i1, name, "i1");
41 checkInstance(y instanceof i2, name, "i2");
42 checkInstance(y instanceof i3, name, "i3");
43 checkInstance(y instanceof i4, name, "i4");
44 checkInstance(y instanceof i5, name, "i5");
45 checkInstance(y instanceof i6, name, "i6");
46 checkInstance(y instanceof i7, name, "i7");
47 checkInstance(y instanceof i8, name, "i8");
50 public static void checkInstance(boolean cond, String obj, String classname) {
51 System.out.printf(obj);
53 System.out.printf(" is instance of ");
54 System.out.printf(classname);
55 System.out.printf(" :-)\n");
57 System.out.printf(" is *not* instance of ");
58 System.out.printf(classname);
59 System.out.printf(" :-(\n");