Java / Methods
Explain the static interface methods feature in Java 8.
The interface static methods are concrete methods implemented in the interface that prevents the implementation classes from overriding to ensure the proper and uniform implementation being used across all the implementation classes.
The static interface method has method body and marked with static keyword in the method signature.
public interface Fruits { static void eat() { System.out.println("Enjoy!"); } }
Java interface static methods are visible to interface methods only and it can be invoked by interface name itself.
public class OrangeClass implements Fruits { public static void main(String[] args) { Fruits.eat(); } }
More Related questions...