class Object1{ //类一
public void tell1(){
System.out.println("Object1 tell1()");
}
public void tell2(){
System.out.println("Object1 tell2()");
}
public void tell4(){
System.out.println("Object1 tell4()");
}
}
class Object2 extends Object1{ //继承类一
public void tell1(){
System.out.println("Object2 tell1()");
}
public void tell3(){
System.out.println("Object2 tell3()");
}
}
public class objectDemo {
//instanceof 方法主要用来判断对象是否属于某个类
public static void main(String[] args) {
Object1 p1=new Object1();
System.out.println(p1 instanceof Object1); //属于类1
System.out.println(p1 instanceof Object2); //不属于类二
Object1 p2=new Object2(); //
System.out.println(p2 instanceof Object1); //属于类1
System.out.println(p2 instanceof Object2); //属于类二
}
}