|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
大一新生,没学过Java .但计算机部要考这个进入.先请帮忙(以后会再学的)
public interface Flyanimal{
public void fly();
}
class Insect {
int legnum=6;
}
class Bird {
int legnum=2;
void egg(){};
}
class Ant extends Insect implements Flyanimal {
public void fly(){
System.out.println("Ant can fly");
}
}
class Pigeon extends Bird implements Flyanimal {
public void fly(){
System.out.println("pigeon can fly");
}
public void egg(){
System.out.println("pigeon can lay eggs ");
}
}
public classInterfaceDemo{
public static void main(String args[]){
Ant a=new Ant();
a.fly();
System.out.println("Ant's legs are"+ a.legnum);
Pigeon p= new Pigeon();
p.fly();
p.egg();
}
} |
|