The practical class implements 2 interfaces. Namely InterA and InterB. The idiom used indicates which of the two default methods you want to call. This is due to the fact that 2 methods have the same signature.
However, when you override the signature in the Practice class as follows:
package practice; interface InterA { public default void AImp() { System.out.println("Calling Aimp from interA"); } } interface InterB { public default void AImp() { System.out.println("Calling Aimp from interB"); } } public class Practice implements InterA, InterB { public static void main(String[] args) { Practice inter = new Practice(); inter.AImp(); }
You will not get the same result. You are getting:
Exception in thread "main" java.lang.StackOverflowError at practice.Practice.AImp(Practice.java:35) at practice.Practice.AImp(Practice.java:35) at practice.Practice.AImp(Practice.java:35) at practice.Practice.AImp(Practice.java:35) at practice.Practice.AImp(Practice.java:35) at practice.Practice.AImp(Practice.java:35) at practice.Practice.AImp(Practice.java:35)
You refer to the Practice instance through the InterA interface, which forces you to use the implemented interface, which will again create the instance. Practice and challenge AImp. This will be recursively repeated until java.lang.StackOverflowError occurs.
source share