Write a Java program to demonstrate interface inheritance with a conflicting default method
interface A { default void sayHello() { System.out.println("Hello from A"); } } interface B { default void sayHello() { System.out.println("Hello from B"); } } class MyClass implements A, B { @Override public void sayHello() { A.super.sayHello(); // Resolve the conflict by specifying the interface B.super.sayHello(); } } public class Main { public static void main(String[] args) { MyClass myClass = new MyClass(); myClass.sayHello(); } }
Hello from A Hello from B
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions