<<< Abstract class compared to interface, cont.     Index     Common java.lang interfaces >>>

6. Interface and abstract class compared

  • Advantages of an abstract class

    • An abstract class can use instance variables and constants as well as static variables and constants. Interfaces can only use static constants

    • An abstract class can define regular methods that contain code as well as abstract methods that don't contain code. An interface can only define abstract methods.

    • An abstract class can define static methods. An interface can't.

  • Advantages of an interface

    • A class can only directly inherit one other class, but it can directly implement multiple interfaces.

    • Any object created from a class that implements an interface can be used wherever the interface is accepted.

<<< Abstract class compared to interface, cont.     Index     Common java.lang interfaces >>>