2 class D
extends C
implements I
{}
4 interface J
extends I
{}
8 static void printIsAssignableFrom(Class a
, Class b
, boolean c
)
10 // The field 'c' can be viewed to see the expected value.
11 System
.out
.println(a
.isAssignableFrom(b
));
14 public static void main (String arg
[])
16 System
.out
.println("Testing class `Class_1'...");
17 printIsAssignableFrom(C
.class, Object
.class, false);
18 printIsAssignableFrom(C
.class, C
.class, true);
19 printIsAssignableFrom(C
.class, D
.class, true);
20 printIsAssignableFrom(D
.class, C
.class, false);
22 printIsAssignableFrom(Object
.class, int[].class, true);
23 printIsAssignableFrom(int[].class, int[].class, true);
24 printIsAssignableFrom(C
[].class, D
.class, false);
25 printIsAssignableFrom(C
[].class, D
[].class, true);
26 printIsAssignableFrom(C
[].class, C
[][].class, false);
28 printIsAssignableFrom(Object
.class, I
.class, true);
29 printIsAssignableFrom(I
.class, I
.class, true);
30 printIsAssignableFrom(D
.class, I
.class, false);
31 printIsAssignableFrom(I
.class, D
.class, true);
33 printIsAssignableFrom(D
.class, J
.class, false);
34 printIsAssignableFrom(J
.class, D
.class, false);
36 printIsAssignableFrom(I
.class, J
.class, true);
37 printIsAssignableFrom(J
.class, J
.class, true);
38 printIsAssignableFrom(J
.class, I
.class, false);
40 // Returns true iff both Class objects are equal.
41 printIsAssignableFrom(long.class, long.class, true);
43 // Does not work for primitive types in general.
44 printIsAssignableFrom(long.class, int.class, false);