// Creating Interface interface GfG{ public default void display() { System.out.println("GEEKSFORGEEKS"); } } // Main Class With Implementation Of Interface public class InterfaceExample implements GfG{ public static void main(String args[]) { InterfaceExample obj = new InterfaceExample(); // Calling Interface obj.display(); } }
Output
GEEKSFORGEEKS
Case 1: When Two Interfaces are not overridden
Java
// Java program to demonstrate the case when // two interfaces are not overridden // Creating Interface One interface GfG{ public default void display() { System.out.println("GEEKSFORGEEKS"); } } // Creating Interface Two interface gfg{ public default void display() { System.out.println("geeksforgeeks"); } } // Interfaces are not Overidden public class InterfaceExample implements GfG,gfg { public static void main(String args[]) { InterfaceExample obj = new InterfaceExample(); obj.display(); } }
Output:
InterfaceExample.java:18: error: types GfG and gfg are incompatible; public class InterfaceExample implements GfG,gfg { ^ class InterfaceExample inherits unrelated defaults for display() from types GfG and gfg 1 error
Case 2: When Two Interfaces are Overridden
Java
// Java program to demonstrate the case // when two interfaces are overridden // Creating Interface One interface GfG{ public default void display() { System.out.println("GEEKSFORGEEKS"); } } // Creating Interface Two interface gfg{ public default void display() { System.out.println("geeksforgeeks"); } } public class InterfaceExample implements GfG,gfg { // Interfaces are Overrided public void display() { GfG.super.display(); gfg.super.display(); } public static void main(String args[]) { InterfaceExample obj = new InterfaceExample(); obj.display(); } }
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.