1.示例:
class A {
public void tell1() {
System.out.println("A--tell1");
}
public void tell2() {
System.out.println("A--tell2");
}
}
class B extends A {
public void tell1() {// 父类方法重写
System.out.println("B--tell1");
}
public void tell3() {
System.out.println("B--tell3");
}
}
public class PolDemo01 {
public static void main(String[] args) {
A a = new A();
System.out.println(a instanceof A);//判断a是否为A的一个对象
System.out.println(a instanceof B);
A a1 = new B();
System.out.println(a1 instanceof A);
System.out.println(a1 instanceof B);
}
}
结果: