封装:隐藏对象内部的复杂性,只对外公开简单的接口。

作用:便于外界调用,从而提高了系统的可扩展性、可维护性。

  同一个类 同一个包 子类      所有类  
private *      
default * *    
protected * * *  
public * * * *

默认default

要点:

1、一般的成员变量用private

    写相应的public的set、get方法来访问相关属性。(注:boolean变量的get方法以is开头)

2、常量或static变量可以公开。

 如:public static int schoolName;

      public static final int MAX_SPEED=120;