Public:visible to the world.
Protected: visible to the package and all subclasses .
Default: visible to the package. No modifiers are needed.
Private: visible to the class only.
修饰类: Default 或者 public
修饰变量或者方法:四种都可以,但是还是有限制
修饰词 | 本类 | 同一个包的类 | 继承类 | 其他类 |
---|---|---|---|---|
private | √ | × | × | × |
无(默认) | √ | √ | × | × |
protected | √ | √ | √ | × |
public | √ | √ | √ | √ |