class base{
???? intx = 1;
???? staticinty = 2;
???? String name () {
???????? return"mother";
????}
???? static String Staticname () {
???????? return"static mother";
????}
}
class Subclass extends base{
???? intx = 4;
???? inty = 5;
???? intZ = 6;
???? String name () {
???????? return"Baby";
????}
???? static String Staticname () {
???????? return"static Baby";
????}
}
Public class test02{
???? Public staticvoid main (string[] args) {
???????? Subclass s = new subclass ();
???????? if(s instanceof subclass) {
???????????? System. out. println (S.x+""+s.y+ ""+s.name () + ""+s. Staticname ());
?
????????}
????????
???????? Base S1 = s;
???????? if(S1 instanceof subclass) {
???????????? System. out. println (S1. X+""+s1. y + ""+s1.name () +""+s1. Staticname());
????????
????????}
????????
???????? Base s2 = new base ();
???????? if(S2 instanceof subclass) {
???????????? System. out. println (S2. X+""+s2. y + ""+s2.name () +""+s2. Staticname());
????????
????????}
????????
????}
}
/*
Results:
4 5 Baby static Baby
1 2 baby static mother
?
Conclusion:
instanceof used to determine the object A is a class B the object, or A, b whether there is an inheritance relationship between
if A, b There is no inheritance relationship, the compilation is
?
*/
Java's instanceof