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 }

 

posted @ 2013-04-01 20:28  glt66  阅读(226)  评论(0编辑  收藏  举报