您的位置:首页 > 其它

通过继承扩展子类的功能

2016-04-04 18:21 246 查看
/*通过继承扩展子类的功能*/

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();

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: