23.实现一个名为Person的类和它的子类Employee,Employee有两个子类Faculty
和Staff。
具体要求如下:
(1)Person类中的属性有:姓名name(String类型),地址address(String类型),
电话号码telphone(String类型)和电子邮件地址email(String类型);
(2)Employee类中的属性有:办公室office(String类型),工资wage(double
类型),受雇日期hiredate(String类型);
(3)Faculty类中的属性有:学位degree(String类型),级别level(String类型);
(4)Staff类中的属性有:职务称号duty(String类型)。
1 public class Person 2 { 3 String name; 4 String address; 5 String telphone; 6 String email; 7 }
1 public class Employee extends Person 2 { 3 String office; 4 String wage; 5 String hiredate; 6 }
1 public class Faculty extends Employee 2 { 3 String degree; 4 String level; 5 }
1 public class Staff extends Employee { String duty; }
24.编写一个Car类,具有String类型的属性品牌,具有功能drive;
定义其子类Aodi和Benchi,具有属性:价格、型号;具有功能:变速;
定义主类E,在其main方法中分别创建Aodi和Benchi的对象并测试对象的特
性。
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 }
时间: 2024-10-17 13:36:25