In Java, an interface cannot implement another interface.
interface MainInterface { void mainMethod(); } interface SubInterface extends MainInterface { // If we put <strong>implements </strong>keyword in place of <strong>extends, </strong>// compiler throws an error. void subMethod(); } class MainClass implements MainInterface { public void mainMethod() { System.out.println("Main Interface Method"); } public void subMethod() { System.out.println("Sub Interface Method"); } } public class Test { public static void main(String args[]) { MainClass main = new MainClass(); main.mainMethod(); main.subMethod(); } }
Main Interface Method Sub Interface Method
The above is the detailed content of Why can't one interface implement another interface in Java?. For more information, please follow other related articles on the PHP Chinese website!