首页 > 代码库 > 0920-继承练习

0920-继承练习

23.实现一个名为Person的类和它的子类EmployeeEmployee有两个子类Faculty

Staff

具体要求如下:

1Person类中的属性有:姓名nameString类型),地址addressString类型),

电话号码telphoneString类型)和电子邮件地址emailString类型)

2Employee类中的属性有:办公室officeString类型),工资wagedouble

类型),受雇日期hiredateString类型)

3Faculty类中的属性有:学位degreeString类型),级别levelString类型)

4Staff类中的属性有:职务称号dutyString类型)

1 public class Person2 {3     String name;4     String address;5     String telphone;6     String email;7 }
1 public class Employee extends Person2 {3     String office;4     String wage;5     String hiredate;6 }
1 public class Faculty extends Employee2 {3     String degree;4     String level;5 }

 1 public class Staff extends Employee  {  String duty;  } 

24.编写一个Car类,具有String类型的属性品牌,具有功能drive

定义其子类AodiBenchi,具有属性:价格、型号;具有功能:变速;

定义主类E,在其main方法中分别创建AodiBenchi的对象并测试对象的特

性。

 1 public class Car  {  String pinpai;  } 

 1 public class Aodi  2 { 3     double jiage; 4     String xinghao; 5      6      7     public double getJiage() { 8         return jiage; 9     }10     public void setJiage(double jiage) {11         this.jiage = jiage;12     }13     public String getXinghao() {14         return xinghao;15     }16     public void setXinghao(String xinghao) {17         this.xinghao = xinghao;18     }19 }
 1 public class Benchi  2 { 3     double jiage; 4     String xinghao; 5      6      7     public double getJiage() { 8         return jiage; 9     }10     public void setJiage(double jiage) {11         this.jiage = jiage;12     }13     public String getXinghao() {14         return xinghao;15     }16     public void setXinghao(String xinghao) {17         this.xinghao = xinghao;18     }19 }
 1 public class E { 2  3     public static void main(String[] args) 4     { 5         Aodi a = new Aodi(); 6         Benchi b = new Benchi(); 7         a.jiage=100; 8         a.xinghao="a6L"; 9         b.jiage=200;10         b.xinghao="s400";11         System.out.println(a.getJiage()+" "+a.xinghao);12         System.out.println(b.getJiage()+" "+b.xinghao);13     }14 15 }

 

0920-继承练习