java作业,求代码
//第20题publicclassPrinterextendsOutputimplementsProduct{
Printer(Stringname){
super(name);
}
publicstaticvoidmain(String[]args){
Printerp=newPrinter("路由器");
p.in();
p.out();
}
@Override
publicvoidin(){
System.out.println(name+"接受信号!");
}
}
interfaceProduct{
voidin();
}
classOutput{
Stringname;
Output(Stringname){
this.name=name;
}
publicvoidout(){
System.out.println(name+"发射信号!");
}
}
//第21题
publicclassDay04_A{
publicstaticvoidmain(String[]args){
newDay04_A().show();
}
privatevoidshow(){
method(newProduct(){//匿名接口参数
publicvoidshow(){
System.out.println("机器设备正在作业!");
}
});
method(newDevice("打印机","数据","打印"){});//匿名抽象参数
method(newMach("火车","电力","运输"));//匿名继承参数
}
privatevoidmethod(Productp){
if(pinstanceofDevice){
Deviced=(Device)p;
d.show();
}else{
p.show();
}
}
}
interfaceProduct{//接口!
publicvoidshow();
}
abstractclassDeviceimplementsProduct{//抽象类
publicStringname,recs,work;
Device(Stringname,Stringrecs,Stringwork){
this.name=name;
this.recs=recs;
this.work=work;
}
@Override
publicvoidshow(){
System.out.println(name+"获取:"+recs+"正在:"+work);
}
}
classMachextendsDevice{//继承
Mach(Stringname,Stringrecs,Stringwork){
super(name,recs,work);
}
}
多重随机标签