最近常遇到如下的描述,希望高手能为我解答
when you creat a package-access class, it still make sense to make the field of the class private创建宝访问权限类时,仍然要将类的字段名设为private才有意义。请问:“类的字段名是何物(the field of the class)”因为类的封装只有包何public,所以这个类的字段肯定不是类名,那又是什么呢?类的方法,类的成员?

解决方案 »

  1.   

    就是属性。例如
    public class Employee {
       
       private String name;//filed
       private int age;//filed   public String getName(){...}
       ...
    }
      

  2.   

    你的例子说明了什么问题?
    Name和age是类的字段?
      

  3.   

    字段(field)是JAVA特有的叫法, 其实就是成员变量(直接定义在类下面的变量).
      

  4.   

    是属性
    这里的field相当于property的意思,不要太拘泥于英文单词