我似乎无法找到为什么我无法创建新的电梯对象。 这是我的Lift类,如下所示:
public class Lift {
private int liftID;
private int People;
private boolean availability;
public Lift(int liftID, int People, boolean availability) {
this.liftID = liftID;
this.People = People;
this.availability = availability;
}
public int getLiftID() {
return liftID;
}
public int getPeople() {
return People;
}
public boolean getAvailability(){
return availability;
}
public boolean isAvailability() {
return availability;
}
这是我的主要课程:
Lift l1 = new Lift();
Lift l2 = new Lift();
Lift l3 = new Lift();
Lift l4 = new Lift();
我似乎无法创建任何Lift对象,希望有人可以帮助我
答案 0 :(得分:2)
错误是因为你的构造函数有3个参数
public Lift(int liftID, int People, boolean availability)
所以在创建对象时你应该传递3个参数。
更改此
Lift l1 = new Lift();
类似
Lift l1 = new Lift(arg1, arg2, arg3);
您可以通过创建另一个没有参数的构造函数来以另一种方式执行此操作。
public Lift() {
//some code or keep it empty
}
之后,您可以像创建List
对象一样创建。{/ p>
Lift l1 = new Lift();