关于实现引用类型数组去调用引用类的方法的问题的解决

为什么不可以使用引用数组的对象school调用引用类School的方法open???

class School{
   private boolean isOpen = false;
    public void open(){
        this.isOpen = true;
    }
    public boolean isOpen(){
        return this.isOpen;
    }
}

publib class Test{
    School[] school = new School[2];
    School higher = new 
    School("higher");
    School primary = new 
    School("primary");
    school[0] = higher;
    school[1] = primary;
    //school.open();//error! why??  
    higher.open();//right!
}







你可能感兴趣的:(Java)