第三题:
(1) void md()、void ma()、void mb()、void mc()
(2) (IA) ic.ma(); (IB) ic.mb(); ic.mc(); (ID) id.md();
(3) True、 true、 true、 true、 true
第四题:true、 true、 true、 true
第五题:ACDE
第六题:Red Light shine in Red Yellow Light shine in Yellow Green Light shine in Green
第七题:TeacherA teach java Teacher8 teach java
第八题:1.for(int i = 0; I < as.length; i++ ){
As[i].eat();
}
2.for(int I = 0; I < as.length; i++){
If(as[i] instanceof Pet){
Pet p = (Pet)as[i];
p.play();
}
}
第九题“
package com.qf.day18.t3.usb;
import java.util.Scanner;
public class TestEmployee {
public static void main(String[] args) {
Employee[] es = new Employee[4];
es[0] = new SalariedEmployee("John",5,5000);
es[1] = new HourlyEmployee("Tom",3,24,170);
es[2] = new SalesEmployee("Lucy", 7,10000,0.04);
es[3] = new BasePlusSalesEmployee("James",8,100000,0.03,5000);
//统计加班费
double sum = 0;
for(int i = 0; i < es.length; i++) {
if(es[i] instanceof Overtime) {
Overtime ot = (Overtime) es[i];
sum += ot.getOvertimePay();
}
}
System.out.println(sum);
}
}
interface Overtime{
double getOvertimePay();
}
class Employee{
private String name;
private int birthMonth;
public Employee(String name,int birthMonth) {
this.name = name;
this.birthMonth = birthMonth;
}
public String getName() {
if(this.birthMonth == month) return 100;{
else return 0;
}
}
}
class SalariedEmployee extends Employee implements Overtime{
private double salary;
public SalariedEmployee(String name,int birthMonth,double salary) {
//把name,birthMonth,两个参数传给父类,设置父类属性
super(name,birthMonth);
this.salary = salary;
}
public double getSalary(int month) {
return salary + super.getSalary(month);
}
public double getOvertimePay() {
return 2000;
}
}
class HourlyEmployee extends Employee{
private double salaryPerHour;
private int hours;
public HourlyEmployee(String name, int birthMonth, double salaryPerHour, int hours) {
super(name,birthMonth);
this.salaryPerHour = salaryPerHour;
this.hours = hours;
}
public double getSalary(int month) {
double result = 0;
if(hours > 160) {
result = 160this.salaryPerHour + (hours-160)this.salaryPerHour1.5;
}else {result = this.hoursthis.salaryPerHour;
return result + super.getSalary(month);
}
}
}
class SalesEmployee extends Employee{
private double sales;
private double rate;
public SalesEmployee(String name, int birthMonth,double sales,double rate) {
super(name,birthMonth);
this.sales = sales;
this.rate = rate;
}
public double getSalary(int month){
return this.sales * this.rate + super.getSalary(month);
}
}
class BasePlusSalesEmployee extends SalesEmployee implements Overtime{
private double basedSalary;
public BasePlusSalesEmployee(String name,int birthMonth,double sales, double rate,double basedSalary) {
this.basedSalary = basedSalary;
}
public double getSalary(int month) {
return this.basedSalary + super.getSalary(month);
}
public double getOvertimePay() {
return 1000;
}
}
第十题
如果实现Servicelmpl接口,则必须实现其所有方法,而如果继承AbstractService类,则只需要覆盖其中我们感兴趣的方法即可。在实际开发中,往往既提供接口,又提供抽象类。既可以提供接口灵活性的基础,也能够使用抽象类来减少代码量
第十一题
import java.util.Scanner;
public class Gedebahe {
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int m=scan.nextInt();
if(m%2!=0 || m<=6) {
System.out.println(“输入错误…”);
}
for(int n=2;n<=m;n++){
for(int y=m;y>n;y–){
if(fan(n)&&fan(y)){
if(n+ym) {
System.out.print(m+"="+y+"+"+n+" “);
System.out.print(”\n");
}
}
}
}
scan.close();
}
public static boolean fan(int x){ //素数判断
for(int i=2;i<x;i++){
if(x%i0){
return false;
}
}
return true;
}
}