More differences between interfaces and abstract classes
Differences between abstract classes and interfaces
Abstract classes can have variables that are or are not defined and we have to provide access modifiers to members in abstract classes
In case of Interfaces all variables are public ,static and final by default so we can't provide those keywords to them and they are by default.
abstract classes methods can be public ,private etc.
Abstract classes can have constructors as well that is not possible in Interfaces.But abstract classes can never be instantiated
Abstract class can extend only one parent class but can implement mmutiple interfaces
Abstract can use static and non static methods and variables.Abstract classes is used to provide a common definition of a base class that multiple child classes can share
Interfaces can't be instantiated. Neither can be abstract classes.All methods in interface are public and final.
Interfaces can implement another interface
Starting with Java 8, default and static methods may have implementation in the interface definition.
In jave 9 private and private static methods were added to interfaces
Interfaces are used to implement common behaviour when we are not concerned about who actually implements that behavior
List interface is an example of interface where ArrayList and LinkedList implement that interface.
When to user interface. When unrelated classes implement our interface we can use interface.
If we have closely related classes that extend a base class we use abstract classes.