/*通过继承扩展子类的功能*/
class Person12{
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void prin(){
System.out.println("名字:"+name+", 年龄:"+age);
}
}
class Student1 extends Person12{
private String school;
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public void pri(){
System.out.println("学校:"+school);
}
}
public class ExtendsDemo1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student1 st2 = new Student1();
st2.setName("张三");
st2.setAge(28);
st2.setSchool("清华大学");
st2.prin();
st2.pri();
}
}
class Person12{
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public void prin(){
System.out.println("名字:"+name+", 年龄:"+age);
}
}
class Student1 extends Person12{
private String school;
public String getSchool() {
return school;
}
public void setSchool(String school) {
this.school = school;
}
public void pri(){
System.out.println("学校:"+school);
}
}
public class ExtendsDemo1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Student1 st2 = new Student1();
st2.setName("张三");
st2.setAge(28);
st2.setSchool("清华大学");
st2.prin();
st2.pri();
}
}