class Test {
public static void main(String[] args) {
dog d = new dog("旺财");
System.out.println(d.getName());
//dog类继承了父类的getName()方法,但是他没有name成员变量,getName()方法里的this.name,这个this不应该是“旺财”这个对象吗?这个对象存在堆中并没有name成员变量啊?
}
}
class animal {
private String name;
public animal() {
}
public animal(String name) {
this.name=name;
}
public void setName(String name) {
this.name=name;
}
public String getName() {
return this.name;
}
}
class dog extends animal {
public dog() {
}
public dog(String name) {
super(name);
}
}