package cn.itcast.test1;
class Parent{
public Object getObject(){
return this;
}
}
class Son extends Parent{
}
public class Test1 {
public static void main(String[] args) {
Son son = new Son();
Son tem = (Son) son.getObject();
if(son==tem)
System.out.println("their this are the same!");
else
System.out.println("their this are the different!");
}
}
class Parent{
public Object getObject(){
return this;
}
}
class Son extends Parent{
}
public class Test1 {
public static void main(String[] args) {
Son son = new Son();
Son tem = (Son) son.getObject();
if(son==tem)
System.out.println("their this are the same!");
else
System.out.println("their this are the different!");
}
}
结果:
their this are the same!
可以看出子类继承父类掉用父类的方法是中的this是子类。