Java 7 and lower version interfaces :
In java 7 and the lower version, the interfaces can have only abstract methods. You can use the “public ” access modifier for the abstract methods and if you didn’t mention any access modifier, it will be considered as public by default.
Java 8 Interfaces :
- Java 8 can have abstract methods as wells as methods with implementation. The methods with implementation should have an “access modifier” default or static.
- The methods with implementation cannot be public or without any access modifier.
- The abstract methods can have a ‘public or no access modifier’.
If two interfaces have the same default method and if the two interfaces are implemented by a class, the class should provide the implementation for the default method. Complier will force this.
Java 9 interfaces :
Java 9 can have private methods. With private methods, it can have default, static, abstract and private static access modifiers.
Difference between java 8 functional interfaces and abstract classes:
- Interfaces in java 8 with implementation methods look like an abstract class. But Abstract class can have ‘state ‘ (property declaration) where the interface cannot have the state. It can have have only constant variables with an initial value.
- An abstract class can have constructor butInterfaces cannot have a constructor.
- With java functional interface, you can have only one abstract method. But with an abstract class, you can have any number of abstract methods.