abstract class Door {
abstract void open();
abstract void close();
}
interface Alarm {
void alarm();
}
class AlarmDoor extends Door implements Alarm {
void open() { … }
void close() { … }
    void alarm() { … }
}

解决方案 »

  1.   

    接口可以定义一个对象的,但是你不能用new生成这个对象,你必须用实现这个接口的一个类来实现这个对象.
      

  2.   

    interface Inter{
     public void doAct();
    }public class Test implements Inter{ //实现了Inter接口
     public void doAct(){ 
      System.out.println("do action");
     } public void static main(String[] args){
      Inter in = new Test();    //可以做接口的引用,但不能直接实例化接
    口,但可以用实现来。
      in.doAct();
     }
    }
      

  3.   

    interface a {
    String s; //public static
    }
    ??
      

  4.   

    interface Inter{
     public void doAct();
    }public class Test implements Inter{ //实现了Inter接口
     public void doAct(){ 
      System.out.println("do action");
     } public void static main(String[] args){
      Inter in = new Test();    //可以做接口的引用,但不能直接实例化接
    口,但可以用实现来。
      in.doAct();
     }
    }
      

  5.   

    interface a{
    }class b implements a{}class c {
     function c(){
       a = new b();
      }
    }
      

  6.   

    package test;import java.lang.System;interface MyInterface
    {
    public int exec();
    }class Return
    {
    public MyInterface exec()
    {
    return ( new MyInterface()
    {
    public int exec()
    {
    return 1;
    }
    }
    );
    }
    }public class TestInterface
    {
    public static final void main( String[] argv )
    {
    Return aReturn = new Return();
    MyInterface aMyInterface = aReturn.exec();
    java.lang.System.out.println( "return value: " + aMyInterface.exec() );
    }
    }
    调用结果
    return value: 1