欢迎来到天天文库
浏览记录
ID:32935567
大小:60.71 KB
页数:8页
时间:2019-02-17
《类继承与接口(二)实验报告》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验十类继承与接口(二)课程名称:面向对象程序设计实验实验项目名称:实验十类继承与接口(二)学生姓名:_专业:_学号:实验地点:实验日期:_年—月—【实验目的】1.掌握Java类的继承特点,包括子类声明、对彖创建、成员变量的继承与隐藏、成员方法的继承与重写【实验内容】10-1程序阅读分析题。要求(1)有一个abstract类,类名为Employee<,Employee的子类有丫earWorker,MonthWorker和WeekWorker。YearWorker对象按年领取薪水,MonthWorker按月领取薪水,WeekWorker按周领取薪水。
2、Employee类有一个abstract方法,子类必须重写父类的earings()方法,给出各自领取报酬的具体方式。(2)有一个Company类,该类用employee数组作为成员,employee数组的单元可以是丫earWorker对象的上转型对象,MonthWorker对象的上转型对象或者WeekWorker对象的上转型对象。源程序:(请将源程序中补充的空缺代码处以下划线加粗显示):abstractclassEmployee!publicabstractdoubleearnings();}classYearWorkerextendsEmploy
3、ee{〃重写earnings()方法代码1:}classMonthWorkerextendsEmployee{//重写earnings()方法代码2:classWeekWorkerextendsEmployee!〃重写earnings()方法代码3:1classCompany{Employee[]employee;doublesalaries=O;Company(Employee[]employee){this.employee=employee;publicdoublesalariesPay(){salaries=O;〃计算salaries代码4
4、:returnsalaries;publicclassHardWork{publicstaticvoidmain(Stringargs[]){Employee[]employee=newEmployee[20];for(inti=0;i5、y=newCompany(employee);System.out.println(,,公司年工资总额:^company.salariesPayO);abstractclassEmployee{publicabstractdoubleearnings();}classYearWorkerextendsEmployee}〃重写earnings()方法publicdoubleearnings(){return80000.0;}}classMonthWorkerextendsEmployee{publicdoubleearnings(){return606、000.0;}}classWeekWorkerextendsEmployee{publicdoubleearnings(){return40000.0;}}classCompany{Employee[]employee;doublesalaries=0;Company(Employee[]employee){this.employee=employee;}publicdoublesalariesPay(){salaries=0;for(inti=0;i7、].earnings();}returnsalaries;}}publicclassHardWorkfpublicstaticvoidmain(Stringargs[]){Employee[]employee=newEmployee[20];for(inti=0;i8、;Companycompany=newCompany(employee);System.out.printlnC'公司年工
5、y=newCompany(employee);System.out.println(,,公司年工资总额:^company.salariesPayO);abstractclassEmployee{publicabstractdoubleearnings();}classYearWorkerextendsEmployee}〃重写earnings()方法publicdoubleearnings(){return80000.0;}}classMonthWorkerextendsEmployee{publicdoubleearnings(){return60
6、000.0;}}classWeekWorkerextendsEmployee{publicdoubleearnings(){return40000.0;}}classCompany{Employee[]employee;doublesalaries=0;Company(Employee[]employee){this.employee=employee;}publicdoublesalariesPay(){salaries=0;for(inti=0;i7、].earnings();}returnsalaries;}}publicclassHardWorkfpublicstaticvoidmain(Stringargs[]){Employee[]employee=newEmployee[20];for(inti=0;i8、;Companycompany=newCompany(employee);System.out.printlnC'公司年工
7、].earnings();}returnsalaries;}}publicclassHardWorkfpublicstaticvoidmain(Stringargs[]){Employee[]employee=newEmployee[20];for(inti=0;i8、;Companycompany=newCompany(employee);System.out.printlnC'公司年工
8、;Companycompany=newCompany(employee);System.out.printlnC'公司年工
此文档下载收益归作者所有