fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. B b = new C();
  13. b.methodWhichCallsMethodOnInterface();
  14. }
  15. }
  16.  
  17. interface A{
  18. default public void method1(){
  19. System.out.println("method1 printing from interface A");
  20. }
  21. default public void method2(){
  22. method1(); // note that method1() is overriden in class C.
  23. // which one should be called? from A or C?
  24. }
  25. }
  26.  
  27. interface B extends A{
  28. void methodWhichCallsMethodOnInterface();
  29. }
  30.  
  31. class C implements B{
  32. @Override
  33. public void method1(){
  34. System.out.println("method1 printing from class C");
  35. }
  36.  
  37. @Override
  38. public void methodWhichCallsMethodOnInterface(){
  39. method2();
  40. }
  41. }
Success #stdin #stdout 0.04s 2184192KB
stdin
Standard input is empty
stdout
method1 printing from class C