With the addition of default methods in interfaces, what is the difference between abstract classes and interfaces?
-
2Hi, Welcome to Stack Overflow! Please see [how to ask](https://stackoverflow.com/help/how-to-ask). Before posting any question here, first do some research google your question and I'm sure for this question if you google it you will find many tutorials that can explain you things far better than what we could answer it here. Hope you understand. Happy Coding :) – rbashish Nov 23 '18 at 05:12
-
I don't see why you mentioned Java 9. I don't remember there is any significant change on this in Java 9/10/11, other than having private method. – Jai Nov 23 '18 at 05:46
2 Answers
The main difference between an abstract class and interface in Java 8 is the fact that an abstract class is a class and an interface is an interface.
A class can have a state which can be modified by non-abstract methods but an interface cannot have the state because they can't have instance variables.
The second difference is that an interface cannot have a constructor even in Java 8 but you may remember that abstract class always has a constructor in Java.
In reality, default or defender methods are introduced to maintain backward compatibility and same time making Collection API more suitable to be used inside key Java 8 features like lambda expressions.
Without adding default methods, it wasn't possible to declare any new method on existing interface in Java without breaking all classes which implement it, but because of default method, you can now better evolve your API.
They defend your code against implementing new methods hence they are also called defender methods.

- 688
- 6
- 21
- Java 9 interfaces still cannot contain constructors.
- Java 9 interfaces still cannot have non-static members.
these are big difference and not multiple inheritance IMO.