为什么我的代码将 null 作为输出值而不是传递的参数?
家长班级:
class Language{
protected String name;
protected int numSpeakers;
protected String regionsSpoken;
protected String wordOrder;
public Language(String getName, int getNumSpeakers, String getRegionsSpoken, String getWordOrder){
this.name = getName;
this.numSpeakers = getNumSpeakers;
this.regionsSpoken = getRegionsSpoken;
this.wordOrder = getWordOrder;
}
public void getInfo(){
System.out.println(name+ " is spoken by "+numSpeakers+" people mainly in "+regionsSpoken);
System.out.println("The language follows the word order: "+wordOrder);
}
public static void main(String[] args){
Mayan mayanLanguage = new Mayan("Ki'che'",30000);
mayanLanguage.getInfo();
}
}
儿童班:
class Mayan extends Language {
protected String name;
protected int numSpeakers;
Mayan(String languageName,int speakers ){
super(languageName,speakers,"Central America","verb-object-subject");
}
@Override
public void getInfo() {
System.out.println(name+" is spoken by "+numSpeakers+" people mainly in Central America.");
System.out.println("The language follows the word order: verb-object-subject");
System.out.println("Fun fact: "+name+" is an ergative language.");
}
}
我查看了代码并尝试通过更改来解决它,但似乎没有任何效果,我陷入了代码中没有看到的错误是什么。
预期是:
Ki'che' 有 2330000 人使用,主要分布在中美洲。该语言遵循词序:动词-宾语-主语 有趣的事实:Ki'che' 是一种作格语言。
实际是:
null 主要在中美洲有 0 人使用。该语言遵循词序:动词-宾语-主语 有趣的事实:null 是一种作格语言。
摇曳的蔷薇
相关分类