package com.hspedu.instanceof_;
import org.junit.Test;
public class TestInstanceof {
@Test
public void testInstanceof() {
Son son = new Son();
System.out.println(son instanceof Son); // true
System.out.println(son instanceof Father); // true
Father father = new Son();
System.out.println(father instanceof Father); // true
System.out.println(father instanceof Son); // true
System.out.println(father instanceof Object); // true
}
}
class Father {
}
class Son extends Father {
}
instanceof是判断对象的运行类型是否是改类,或其子类