这个Java类有什么问题?

Spa*_*Man 0 java variables

每次我在主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)

Sib*_*bbo 6

你把你的构造函数的开头大括号发表评论:

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)