关于private,default,protected,public,成员变量访问权限
关于private,protected,public,default成员变量的访问权限,请参阅上图!
子类要访问父类的private成员变量,必须采用采用get方法:
eg:
public class Humans { public String sex; protected int age ; private String name; Humans(String sex,String name,int age){ this.sex = sex; this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
System.out.println(s.getName())