gpt4 book ai didi

java - 无法访问数组的 "length"属性

转载 作者:行者123 更新时间:2023-12-02 08:11:05 24 4
gpt4 key购买 nike

我创建了一个继承自员工类的 Manager 类...当我尝试访问“Employee”类型(父类)的数组“managementEmployee”的长度属性时,我遇到了问题..

有人可以告诉我我无法访问 nangedEpployee 数组的长度属性的原因吗??????
谢谢..

public class Manager extends Employee {

int index = 0;
private Employee[] managedEmployee = new Employee[10];

public void inputManagedEmployee(Employee e) {

if (e == null) {

System.out.println("invalid Employee");

} else {
for (int x = 0; x < managedEmployee.length; x++) {

managedEmployee[index] = e;
index++;
}

}
}

public void displayManagerInfo() {

System.out.println("The name of the candidate is :" + getName());
System.out.println("The Id of the candidate is:" + getID());
System.out.println("The level of the candidate is :" + getLevel());
System.out.println("the Title of the candidate is :" + getTitle());

for (int x = 0; x <= index; x++) {
if (managedEmployee[x] != null) {
System.out.println("The name of the managed candidate is :"
+ managedEmployee[x].getName());

}
}

}
}

最佳答案

managementEmployee.lenght 拼写错误。应该是managementEmployee.length

我还猜测在您的 for 循环中,其中显示的 managementEmployee[index]=e; 应该是 managementEmployee[x]= e;

关于java - 无法访问数组的 "length"属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7410738/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com