不太清楚为什么,但 Eclipse 在我的 setter 方法上出现错误,显示“语法错误,插入“...VariableDeclaratoid”以完成 FormalParamaterList。”
这是我的代码:
public class Student {
public int id;
public String name;
Student() {
}
public int getID() {
return id;
}
public void setID(i) {
this.id = i;
}
public String getName() {
return name;
}
public void setName(n) {
this.name = n;
}
public String toString() {
System.out.println("The student's name is: " + this.name);
System.out.println("The student's ID is: " + this.id);
}
}
最佳答案
因为您没有指定参数 i
和 n
的类型。见下文
public void setID(int i) {
this.id = i;
}
public void setName(String n) {
this.name = n;
}
关于java - 对象的设置方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47585002/