每次我在主Java类上创建一个新的Dog对象时,我都无法用我想要的字符串替换"null"(它表示Dog类中的String Name变量).这是班级:
private String Name;
private int Age;
public Dog(String Name, int Age) //Constructor {
this.Name =(String) Name;
this.Age = Age;
}
public int getAge() {
return Age;
}
public void setAge(int Age) {
this.Age = Age;
}
public String getName() {
return Name;
}
public void setName(String Name) {
this.Name = Name;
}
Run Code Online (Sandbox Code Playgroud)
你把你的构造函数的开头大括号发表评论:
public Dog(String Name, int Age) //Constructor { <-- Brace is part of comment
Run Code Online (Sandbox Code Playgroud)
解:
public Dog(String Name, int Age) /*Constructor*/ {
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
127 次 |
| 最近记录: |