class Person {
String name;
int age;
public String talk() {
return "我是:"+name+",今年:"+age+"岁";
}
}
class Student extends Person {
String school;
public Student(String name,int age,String school) {
super.name = name;
super.age = age;
this.school = school;
}
public String talk() {
return "学校:"+school;
}
}
public class Test001 {
public static void main(String[] args) {
Student s = new Student("张三",20,"上海交大");
System.out.println(new Person().talk());
}
}
如上代码,我用有参构造方法给对象初始化,并且用super关键字赋值给了父类name、age,
为何调用父类方法的时候却显示“我是:null,今年:0岁”,并没有赋值给父类的属性,
百思不得骑姐,求大神解答,感谢!
|
|