Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7563623
  • 博文数量: 961
  • 博客积分: 15795
  • 博客等级: 上将
  • 技术积分: 16612
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-07 14:23
文章分类

全部博文(961)

文章存档

2016年(1)

2015年(61)

2014年(41)

2013年(51)

2012年(235)

2011年(391)

2010年(181)

分类: Java

2012-04-12 21:36:25


点击(此处)折叠或打开

  1. class Person {
  2.     private String name;
  3.     private int age;
  4.     public void setName(String name){this.name=name;}
  5.     public void setAge(int age) {this.age=age;}
  6.     public String getName(){return name;}
  7.     public int getAge(){return age;}
  8.     public String getInfo() {
  9.           return "Name: "+ name + "\n" +"age: "+ age;
  10.   }
  11. }

  12. class Student extends Person {
  13.     private String school;
  14.     public String getSchool() {return school;}
  15.     public void setSchool(String school)
  16.     {this.school =school;}
  17.     public String getInfo() {
  18.       return "Name: "+ getName() + "\nage: "+ getAge()
  19.                     + "\nschool: "+ school;
  20.         }
  21. }

  22. public class TestOverWrite {
  23. public static void main(String arg[]){
  24.         Student student = new Student();
  25.         Person person = new Person();
  26.         person.setName("none");
  27.         person.setAge(1000);
  28.         student.setName("John");
  29.         student.setAge(18);
  30.         student.setSchool("SCH");
  31.         System.out.println(person.getInfo());
  32.         System.out.println(student.getInfo());
  33.     }
  34. }

阅读(1003) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~