While Java Interfaces have been around since Java 1.0. Java version 1.8 (8) enhanced interfaces providing inhertible default methods, static methods and more.
A class must implement all methods that an interface defines, a class can inherit from multiple interfaces using the implements key word with multiple interfaces separated by commas.
interface FirstInterface {
public void firstMethod();
}
interface SecondInterface {
public void secondMethod();
}
public class MyClass implements FirstInterface, SecondInterface {
public void firstMethod() {
System.out.println("Implemented firstMethod of FirstInterface");
}
public void secondMethod() {
System.out.println("Implemented secondMethod of SecondInterface");
}
public static void main(String[] args) {
MyClass myObj = new MyClass();
myObj.firstMethod();
myObj.secondMethod();
}
}