用java编写下面的小程序.内容什么都行,但必须用到接口
答案:2 悬赏:70 手机版
解决时间 2021-01-29 01:24
- 提问者网友:精神病院里
- 2021-01-28 17:07
用java编写下面的小程序.内容什么都行,但必须用到接口
最佳答案
- 五星知识达人网友:妄饮晩冬酒
- 2021-01-28 18:17
interface MyInterface {
void func();
}
class MyClass implements MyInterface {
public void func {
// TODO
}
}
void func();
}
class MyClass implements MyInterface {
public void func {
// TODO
}
}
全部回答
- 1楼网友:一把行者刀
- 2021-01-28 19:31
interface lookafterpet{
public void feed();
public void playwithit();
}
class worker implements lookafterpet {
string name;
public worker(string name){
this.name=name;
}
public void feed(){
system.out.println("the worker:"+name+" feed their pet");
}
public void playwithit(){
system.out.println("the worker:"+name+" playwith their pet");
}
}
class farmer implements lookafterpet {
string name;
public farmer(string name){
this.name=name;
}
public void feed(){
system.out.println("the farmer:"+name+" feed their pet");
}
public void playwithit(){
system.out.println("the farmer:"+name+" playwith their pet");
}
}
class leader implements lookafterpet {
string name;
public leader(string name){
this.name=name;
}
public void feed(){
system.out.println("the leader:"+name+" feed their pet");
}
public void playwithit(){
system.out.println("the leader:"+name+" playwith their pet");
}
}
public class demo {
public static void main(string args[]){
lookafterpet w=new worker("小王");
farmer f=new farmer("李四");
leader l=new leader("王五");
w.feed();
w.playwithit();
feedpet(f);
playwithpet(f);
feedpet(l);
playwithpet(l);
}
public static void feedpet(lookafterpet la){
la.feed();
}
public static void playwithpet(lookafterpet la){
la.playwithit();
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯