Java-15,类的继承与访问控制

 

 

class Person {
private String name;
private int age;
public void setName(String name) {
this.name=name;
}
public void setAge(int age) {
this.age=age;
}
public String getName(){
return name;
}
public int getAge(){
return age;
}
}

class Student extends Person {
private String school;
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school =school;
}
}

public class Test {
public static void main(String arg[]){
Student student = new Student();
student.setName("John");
student.setAge(18);
student.setSchool("SCH");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
}
}

 

 

 

posted @ 2020-03-02 01:52  润青  阅读(182)  评论(0编辑  收藏  举报