What are the main differences between an interface with default method and an abstract class in Java 8?

An interface with a default method appears same as an Abstract class in Java. But there are subtle differences between two.

  • Instance variable: An interface cannot have instance variables. An abstract class can have instance variables.
  • Constructor: An interface cannot have a constructor. An abstract class can have constructor.
  • Concrete Method: An interface cannot have concrete methods other than default method. An abstract class is allowed to define concrete methods with implementation.
  • Lambda: An interface with exactly one default method can be used for lambda expression. An abstract class cannot be used for lambda expression.

Leave a Reply

Your email address will not be published. Required fields are marked *