62,636
社区成员




class Father {
public Father() {
System.out.println("Father");
}
private void hello(Son son) {
System.out.println("hello");
System.out.println(this==son);//输出true,说明this和son引用的是同一个对象
}
public void sayHello(Son son) {
System.out.println(this instanceof Son);
this.hello(son);
}
}
public class Son extends Father {
public static void main(String[] args) {
Son s = new Son();
s.sayHello(s);
}
}
class Father
{
}
class Son extends Father
{
}
public class Test{
public static void main(String[] args)throws Exception{
Father f = new Son();
System.out.println(f instanceof Father);//true
System.out.println(f instanceof Son);//true
Son s = new Son();
System.out.println(s instanceof Father);//true
System.out.println(s instanceof Son);//true
}
}