问题

在Java中,有何时使用每个访问修饰符,即默认(包私有), public , protected private < / code>,同时使 class interface 并处理继承?



解决方法

官方教程可能对您有所帮助.

            | Class | Package | Subclass | Subclass | World
            |       |         |(same pkg)|(diff pkg)| 
____________+_______+_________+__________+__________+________
public      |   +   |    +    |    +     |     +    |   +     
____________+_______+_________+__________+__________+________
protected   |   +   |    +    |    +     |     +    |   o     
____________+_______+_________+__________+__________+________
no modifier |   +   |    +    |    +     |     o    |   o
____________+_______+_________+__________+__________+________
private     |   +   |    o    |    o     |     o    |   o

+ : accessible
o : not accessible



相关问题推荐