首先,我将向您展示我的代码:
public class Person {
String _name;
int _age;
public Person(String name, int age){
_name = name;
_age = age;
}
public String toString(){
return "Age:" + _age + ". Name: " + _name;
}
}
public class Principal extends Person{
String _gender;
int _rank;
public Principal(String name, int age, String gender, int rank){
super(name, age);
_gender = gender;
_rank = rank;
}
public String toString(){
return "Age:" + _age + " .Name: " + _name + " .Gender: " + _gender + " .Rank: " + _rank;
}
}
主要的:
public class Main {
public static void main(String[] args){
Person me = new Person("Bob", 23);
System.out.println(me);
Principal hj = new Principal("Dan", 39, "Male", 1);
}
}
我不明白为什么我必须在Principal hj = new Principal("Dan", 39, "Male", 1);
. . . 我认为super(name, age);
应该从对象继承前两个参数me
,我只需要应用最后两个参数。
我想念什么?