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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ecnuThomas/article/details/79059862

为什么不可以使用引用数组的对象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!
}







猜你喜欢

转载自blog.csdn.net/ecnuThomas/article/details/79059862