我正在用 Java 编写一个小排序程序,旨在抓取一个“学生”对象并确定它的名称、职业和课堂取决于参数和属性。然而,当我尝试创建第一个对象时,出现了一个问题。到目前为止,一切看起来像这样:
public class Student {
private String name, classroom;
/**
* The career code is as follows, and I quote:
* 0 - Computer Science
* 1 - Mathematics
* 2 - Physics
* 3 - Biology
*/
private short career, idNumber;
public Student (String name, short career, short idNumber){
this.name = name;
this.classroom = "none";
this.career = career;
this.idNumber = idNumber;
}
public static void main(String args[]){
Student Andreiy = new Student("Andreiy",0,0);
}
}
该错误出现在对象创建行上,由于某种原因,当构造函数调用短裤时,它坚持将 0,0 解释为整数,从而导致不匹配问题。
有任何想法吗?