1
public class TestClass {
2![](/Images/OutliningIndicators/InBlock.gif)
3
public static void main(String[] args) {
4
5
Parent parent = new Parent();
6
Child child = new Child();
7
8
if (child instanceof Child){
9
System.out.println("child instanceof Child is true!");
10
} else {
11
System.out.println("child instanceof Child is false!");
12
}
13
if (child instanceof Parent){
14
System.out.println("child instanceof Parent is true!");
15
} else {
16
System.out.println("child instanceof Parent is false!");
17
}
18
if (child instanceof Person){
19
System.out.println("child instanceof Person is true!");
20
} else {
21
System.out.println("child instanceof Person is false!");
22
}
23
24
if (Child.class.isInstance(child)){
25
System.out.println("Child.class.isInstance(child) is true!");
26
} else {
27
System.out.println("Child.class.isInstance(child) is false!");
28
}
29
if (Parent.class.isInstance(child)){
30
System.out.println("Parent.class.isInstance(child) is true!");
31
} else {
32
System.out.println("Parent.class.isInstance(child) is false!");
33
}
34
if (Person.class.isInstance(child)){
35
System.out.println("Person.class.isInstance(child) is true!");
36
} else {
37
System.out.println("Person.class.isInstance(child) is false!");
38
}
39
40
if (Child.class.isAssignableFrom(Child.class)){
41
System.out.println("Child.class.isAssignableFrom(Child.class) is true!");
42
} else {
43
System.out.println("Child.class.isAssignableFrom(Child.class) is false!");
44
}
45
if (Child.class.isAssignableFrom(Parent.class)){
46
System.out.println("Child.class.isAssignableFrom(Parent.class) is true!");
47
} else {
48
System.out.println("Child.class.isAssignableFrom(Parent.class) is false!");
49
}
50
if (Child.class.isAssignableFrom(Person.class)){
51
System.out.println("Child.class.isAssignableFrom(Person.class) is true!");
52
} else {
53
System.out.println("Child.class.isAssignableFrom(Person.class) is false!");
54
}
55
//Parent class implemented the Interface 'Person'
56
if (Parent.class.isAssignableFrom(Person.class)){
57
System.out.println("Parent.class.isAssignableFrom(Person.class) is true!");
58
} else {
59
System.out.println("Parent.class.isAssignableFrom(Person.class) is false!");
60
}
61
62
63
if (Child.class.isAssignableFrom(Child.class)){
64
System.out.println("Child.class.isAssignableFrom(Child.class) is true!");
65
} else {
66
System.out.println("Child.class.isAssignableFrom(Child.class) is false!");
67
}
68
if (Parent.class.isAssignableFrom(Child.class)){
69
System.out.println("Parent.class.isAssignableFrom(Child.class) is true!");
70
} else {
71
System.out.println("Parent.class.isAssignableFrom(Child.class) is false!");
72
}
73
if (Person.class.isAssignableFrom(Child.class)){
74
System.out.println("Person.class.isAssignableFrom(Child.class) is true!");
75
} else {
76
System.out.println("Person.class.isAssignableFrom(Child.class) is false!");
77
}
78
//Parent class implemented the Interface 'Person'
79
if (Person.class.isAssignableFrom(Parent.class)){
80
System.out.println("Person.class.isAssignableFrom(Parent.class) is true!");
81
} else {
82
System.out.println("Person.class.isAssignableFrom(Parent.class) is false!");
83
}
84
85
86
87
88
}
89
}
90![](/Images/OutliningIndicators/None.gif)
91![](/Images/OutliningIndicators/None.gif)
92![](/Images/OutliningIndicators/None.gif)
93![](/Images/OutliningIndicators/None.gif)
94![](/Images/OutliningIndicators/None.gif)
95
public class Child extends Parent {
96![](/Images/OutliningIndicators/InBlock.gif)
97
public static void main(String[] args) {
98
}
99
}
100![](/Images/OutliningIndicators/None.gif)
101![](/Images/OutliningIndicators/None.gif)
102![](/Images/OutliningIndicators/None.gif)
103
public class Parent implements Person {
104![](/Images/OutliningIndicators/InBlock.gif)
105
public static void main(String[] args) {
106
}
107
}
108![](/Images/OutliningIndicators/None.gif)
109![](/Images/OutliningIndicators/None.gif)
110![](/Images/OutliningIndicators/None.gif)
111
public interface Person {
112![](/Images/OutliningIndicators/InBlock.gif)
113
}
114![](/Images/OutliningIndicators/None.gif)
115![](/Images/OutliningIndicators/None.gif)
116![](/Images/OutliningIndicators/None.gif)
117![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
2
![](/Images/OutliningIndicators/InBlock.gif)
3
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
13
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
18
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
19
![](/Images/OutliningIndicators/InBlock.gif)
20
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
21
![](/Images/OutliningIndicators/InBlock.gif)
22
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
25
![](/Images/OutliningIndicators/InBlock.gif)
26
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
29
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
34
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
35
![](/Images/OutliningIndicators/InBlock.gif)
36
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
37
![](/Images/OutliningIndicators/InBlock.gif)
38
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
45
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
46
![](/Images/OutliningIndicators/InBlock.gif)
47
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
50
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
51
![](/Images/OutliningIndicators/InBlock.gif)
52
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
53
![](/Images/OutliningIndicators/InBlock.gif)
54
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
55
![](/Images/OutliningIndicators/InBlock.gif)
56
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
58
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
59
![](/Images/OutliningIndicators/InBlock.gif)
60
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
61
![](/Images/OutliningIndicators/InBlock.gif)
62
![](/Images/OutliningIndicators/InBlock.gif)
63
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
64
![](/Images/OutliningIndicators/InBlock.gif)
65
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
66
![](/Images/OutliningIndicators/InBlock.gif)
67
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
68
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
69
![](/Images/OutliningIndicators/InBlock.gif)
70
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
71
![](/Images/OutliningIndicators/InBlock.gif)
72
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
73
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
74
![](/Images/OutliningIndicators/InBlock.gif)
75
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
76
![](/Images/OutliningIndicators/InBlock.gif)
77
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
78
![](/Images/OutliningIndicators/InBlock.gif)
79
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
80
![](/Images/OutliningIndicators/InBlock.gif)
81
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
82
![](/Images/OutliningIndicators/InBlock.gif)
83
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
84
![](/Images/OutliningIndicators/InBlock.gif)
85
![](/Images/OutliningIndicators/InBlock.gif)
86
![](/Images/OutliningIndicators/InBlock.gif)
87
![](/Images/OutliningIndicators/InBlock.gif)
88
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
89
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
90
![](/Images/OutliningIndicators/None.gif)
91
![](/Images/OutliningIndicators/None.gif)
92
![](/Images/OutliningIndicators/None.gif)
93
![](/Images/OutliningIndicators/None.gif)
94
![](/Images/OutliningIndicators/None.gif)
95
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
96
![](/Images/OutliningIndicators/InBlock.gif)
97
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
98
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
99
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
100
![](/Images/OutliningIndicators/None.gif)
101
![](/Images/OutliningIndicators/None.gif)
102
![](/Images/OutliningIndicators/None.gif)
103
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
104
![](/Images/OutliningIndicators/InBlock.gif)
105
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
106
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
107
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
108
![](/Images/OutliningIndicators/None.gif)
109
![](/Images/OutliningIndicators/None.gif)
110
![](/Images/OutliningIndicators/None.gif)
111
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
112
![](/Images/OutliningIndicators/InBlock.gif)
113
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
114
![](/Images/OutliningIndicators/None.gif)
115
![](/Images/OutliningIndicators/None.gif)
116
![](/Images/OutliningIndicators/None.gif)
117
![](/Images/OutliningIndicators/None.gif)