无法访问数组的“length”属性

时间:2011-09-14 02:49:17

标签: java

我创建了一个继承自员工类的Manager类... 我正在尝试访问类型为“Employee”(父类)的数组“managedEmployee”的length属性时遇到问题。

有人能告诉我无法访问nanagedEpployee数组的长度属性的原因???????? 感谢..

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());

         }
      }

   }
}

1 个答案:

答案 0 :(得分:2)

managedEmployee.lenght拼写错误。应为managedEmployee.length

我也猜测在你的for循环中,managedEmployee[index]=e;应该是managedEmployee[x]=e;