What is the difference between an abstract class and an interface when Java 8 introduced default methods in interfaces?

  • An abstract class can contain both abstract and concrete methods, whereas an interface can only have abstract methods.
  • An abstract class cannot be extended, but an interface can be implemented.
  • An abstract class cannot have any methods with default implementations, while an interface can have default methods.
  • An abstract class cannot have constructors, but an interface can have default constructors.
In Java 8, interfaces were enhanced to support default methods, which provide a default implementation. The key difference between an abstract class and an interface is that an abstract class can have both abstract and concrete methods, whereas an interface can only have abstract methods. This allows for multiple inheritance of behavior through interfaces while maintaining the ability to inherit state through abstract classes.
Add your answer
Loading...

Leave a comment

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