Java-子类扩展父类功能

class person
{
 private String name;
 private int age;
 public String getname(){
  return this.name;
 }
 public void setname(String name)
 {
  this.name=name;
 }
 public void setage(int age)
 {
  this.age=age;
 }
 public int getage()
 {
  return this.age;
 }
}
class student extends person
{
 private String school;
 public void setschool(String school)
 {
  this.school=school;
 }
 public String getschool()
 {
  return this.school;
 }
}
public class test29 {
 public static void main(String args[])
 {
  student stu=new student();
  stu.setname("Aaron");
  stu.setage(20);
  stu.setschool("****大学");
  System.out.println("姓名 :"+stu.getname()+"" +"\t年龄:"+stu.getage()+"\t学校:"+stu.getschool());
 }

}

 

posted @ 2013-07-14 23:12  爱生活,爱编程  阅读(590)  评论(0编辑  收藏  举报