接口和抽象类都是需要继承并实现的,JAVA不能多重继承,但可以继承多个接口,间接实现了多重继承,接口、抽象类中定义的方法需要在继承之后的类中实现,其实接口就是一个标准,其中包含了对象实例的共有方法,你可以查JDK的API,会发现有很多的接口和抽象类,比如
public class Vector
extends AbstractList
implements List, Cloneable, Serializable
它继承了AbstractList,同时继承了List, Cloneable, Serializable
AbstractList是抽象类,List, Cloneable, Serializable都是接口,你可以看看它们里面的方法,再对比一下Vector中的方法,理解其中的思想就好!

解决方案 »

  1.   

    还有一个理解接口的方法,在JDBC标准中,定义的都是接口,每种数据库根据不同的情况实现JDBC的接口,在使用不同的JDBC驱动的时候,我们使用的方法都是一样的!
      

  2.   

    我刚买的摩托罗拉天拓A6288,来开发j2me,因感觉有点大,又刚发了3000元工资,决定换一个西门子6688.
    本人不善讨价还价,最低1100,有意的朋友,请发短信:13520929201.
    本机有PDA功能,词典,gprs,kjava,红外线。适合开发用。
    原装锂电池2块,多功能冲电器,数据线,光盘,皮套,发票,包修卡。
    我在北京email:[email protected]
      

  3.   

    JAVA编程语言支持接口,你可以使用接口来定义行为的协议。这些行为可以在类分级结构中的任何类中被执行。
    接口定义了行为的协议,这些行为可以在类分级结构中的任何类中被执行。接口定义了许多方法但是没有执行它们。类履行接口协议来执行所有定义在接口中的方法,因此适合某些行为。 
      因为接口是简单的未执行的系列以及一些抽象的方法,你可能会思考究竟接口于抽象类有什么区别。知道了它们的区别是相当重要的。 它们之间有以下的区别:
    接口不能执行任何的方法,而抽象类可以。 
    类可以执行许多接口,但只有一个父类。 
    接口不是类分级结构的一部分。而没有联系的类可以执行相同的接口。 
      

  4.   

    http://jspzone.myrice.com/beginner/java/javaconcept.htm
      

  5.   

    这几天看<java与模式>,我把书里的话摘一段(书不在手边,不是原话):面象对象的设计,要满足的第一原则是开闭原则,要求设计出来的系统,对修改关闭,对扩展开放。这样设计出来的系统,才能有好的稳定性和扩展性。要满足这样的原则,就需要使用抽象类和接口。
    把系统结构抽象出来,形成抽象的系统结构(一般由抽象类来定义),它要能够满足系统的所有要求,一旦定义后不可被修改,这就满足了对修改关闭。
    如果以后要修改系统结构(比如要修改结构中间的一个类),显示不能修改它的抽象类(因为结构如果很庞大的话,而一个类只能有一个超类,必须一级一级修改直到最顶层的类,这显然不现实),但一个类可以实现任意多个接口,
    给这个类增加一个接口,这个类的功能就得到了扩展,
    这就满足了对扩展开放。用抽象类加接口来定义系统的结构,
    就满足了开闭原则,
    使系统结构更合理。我也是在学习中,以上都是书中的观点,
    如果你还不理解抽象类和接口的语法的话,
    那还需要先掌握这些,
    再体会在设计模式中的用法。
      

  6.   

    What Is an Interface? 
    This section shows you how to create and to use interfaces and talks about why you would use an interface instead of a class. 
    An interface defines a protocol of behavior that can be implemented by any class anywhere in the class hierarchy. An interface defines a set of methods but does not implement them. A class that implements the interface agrees to implement all the methods defined in the interface, thereby agreeing to certain behavior. --------------------------------------------------------------------------------
    Definition: An interface is a named collection of method definitions (without implementations). An interface can also declare constants. 
    --------------------------------------------------------------------------------
    Because an interface is simply a list of unimplemented, and therefore abstract, methods, you might wonder how an interface differs from an abstract class. The differences are significant. 
    An interface cannot implement any methods, whereas an abstract class can. 
    A class can implement many interfaces but can have only one superclass. 
    An interface is not part of the class hierarchy. Unrelated classes can implement the same interface.