Interfaces vs Abstract Classes

Interfaces

  • Only allowed to have public static final variables. All variables must both have a datatype and a value. Final variables are not given default values inherently. The words public static and final are optional.

  • All methods in an interface are inherently public and abstract. Both of these words are optional. Because these methods are abstract they can not have braces {} and the method header must end with a semicolon ;

  • Interfaces are not allowed to have constructors.

  • Interfaces extend other interfaces.

  • Interfaces are implemented by classes.

  • Any class that implements an interface is required to override all methods in the interface

Abstract class

  • Can have any type of variable (instance variable, class (static) variable, final variables. Final variables need to be defined.

  • Can have abstract or concrete methods. Abstract is NOT assumed and must be written.

  • Abstract methods can not have {} braces and must end with a semicolon, non abstract methods must have braces.

  • Should have constructors (public or private) as the abstract class will be the super class for the class which extends it.

  • Abstract classes can extend other classes whether they are abstract or not.

  • Any non abstract class which extends the abstract class must override the abstract methods within that class.