Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7563516
  • 博文数量: 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 20:47:09


点击(此处)折叠或打开

  1. class Person {
  2.     private String name;
  3.     private int age;
  4.     
  5.     public void setName(String name) {
  6.         this.name=name;
  7.     }
  8.     
  9.     public void setAge(int age) {
  10.         this.age=age;
  11.     }
  12.     
  13.     public String getName(){
  14.         return name;
  15.     }
  16.     
  17.     public int getAge(){
  18.         return age;
  19.     }
  20. }

  21. class Student extends Person {
  22.     private String school;
  23.     public String getSchool() {
  24.         return school;
  25.     }
  26.     public void setSchool(String school) {
  27.         this.school =school;
  28.     }
  29. }

  30. public class Test {
  31.     public static void main(String arg[]){
  32.         Student student = new Student();
  33.         student.setName("John");
  34.         student.setAge(18);
  35.         student.setSchool("SCH");
  36.         System.out.println(student.getName());
  37.         System.out.println(student.getAge());
  38.         System.out.println(student.getSchool());
  39.     }
  40. }

课件: 类的继承.pdf   
阅读(1158) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~