Animal中没有Alpha1()的方法,也没有继承

解决方案 »

  1.   

    上面那个没问题
    应该是这个刚才帖错了
    interface Animal {
     void soundOff();
     } class Elephant implements Animal {
     public void soundOff() {
     System.out.println("Trumpet");
     }
     } class Lion implements Animal {
     public void soundOff() {
     System.out.println("Roar");
     }
     } class Alpha1 {
     static Animal get( String choice ) { if ( choice.equalsIgnoreCase( "meat eater" )) {
     return new Lion();
     } else {
     return new Elephant();
     }
     }
     }
    public class Testintface{
    public static void main(String[] args){

     Animal ll= Alpha1().get("meat eater");//.soundOff();
    }
    }
    为什么无法编译
      

  2.   

    Animal ll= Alpha1().get("meat eater");//.soundOff();改成下面这样:
    Animal ll= Alpha1.get("meat eater");//.soundOff();就好了