interface Act{
   void act();
 }
class Actor1 implements Act{
   public void act(){
     System.out.println("To be,or not to be");
 }
}
class  Actor2 implements Act{
   public void act(){
      System.out.println("Wherefore art thou Romeo?");
 }
}
public class TryOut{
  public static void main(String []args){
    Actor1  hamlet=new Actor1();
    Actor2  juliet=new Actor2();
    tryout(hamlet);
    tryout(juliet);
  }
    private  static void tryout(Act  actor){
       actor.act();
  }
}
Actor1,Actor2不是实现接口的方法了吗?语句
    tryout(hamlet);
    tryout(juliet);
    private  static void tryout(Act  actor)
       actor.act();不要了不行吗?

解决方案 »

  1.   

    当然不可以,你这两个类根本没有关系。直接调用
        Actor1  hamlet=new Actor1(); hamlet.act();
        Actor2  juliet=new Actor2(); juliet.act();
    这样当然可以。但是我觉得这个例子是为了说明hamlet和juliet都是Act类型。
      

  2.   

    不要也可以,改成下面:
    public class TryOut{
      public static void main(String []args){
        Actor1  hamlet=new Actor1();
        Actor2  juliet=new Actor2();
      
        hamlet.act();
        juliet.act();
      }
    }
      

  3.   

    同意搂上的,不过这个例子是有点别扭定义了一个私有的静态方法就是为了调用hamlet.act()和juliet.act(),不过,我猜想可能还是有别的原因的,顶上去,希望高手能给个准确的答复
      

  4.   

    。yuzl32(Hello!有酒醉)  有何意义?
      

  5.   

    yuzl32(Hello!有酒醉)说得是正解
      

  6.   

    funcreal(为中华之崛起而编程) ( 一星(中级)) 信誉:100
    #1才是正解yuzl32(Hello!有酒醉)这样做有什么意义。根本体现不了接口的特点。