java权限修饰符
1 class Person { 2 private String name; 3 private int age; 4 public void setName(String name) { 5 this.name=name; 6 } 7 public void setAge(int age) { 8 this.age=age; 9 } 10 public String getName(){ 11 return name; 12 } 13 public int getAge(){ 14 return age; 15 } 16 } 17 18 class Student extends Person { 19 private String school; 20 public String getSchool() { 21 return school; 22 } 23 public void setSchool(String school) { 24 this.school =school; 25 } 26 } 27 28 public class Test { 29 public static void main(String arg[]){ 30 Student student = new Student(); 31 student.setName("John"); 32 student.setAge(18); 33 student.setSchool("SCH"); 34 System.out.println(student.getName()); 35 System.out.println(student.getAge()); 36 System.out.println(student.getSchool()); 37 } 38 }