程序运行后是什么结果
大一新生,没学过Java{:5_99:} .但计算机部要考这个进入.先请帮忙(以后会再学的)public interface Flyanimal{
public void fly();
}
class Insect {
intlegnum=6;
}
classBird {
intlegnum=2;
void egg(){};
}
class Ant extends Insect implementsFlyanimal {
public void fly(){
System.out.println("Ant canfly");
}
}
class Pigeon extends Bird implementsFlyanimal {
public void fly(){
System.out.println("pigeoncan fly");
}
public void egg(){
System.out.println("pigeoncan layeggs ");
}
}
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();
}
} Ant canfly
Ant's legs are 6
pigeoncan fly
pigeoncan layeggs
页:
[1]