fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.lang.reflect.*;
  6. import java.io.*;
  7.  
  8. interface Foo {
  9. default int calc(int a, int b) {
  10. return a + b;
  11. }
  12. }
  13.  
  14. interface Boo {
  15. default void print(int a) {
  16. System.out.println(a);
  17. }
  18. }
  19.  
  20.  
  21. /* Name of the class has to be "Main" only if the class is public. */
  22. class Ideone implements Foo, Boo
  23. {
  24. public static void main (String[] args) throws java.lang.Exception
  25. {
  26. // Multiple inheritance
  27. Ideone obj = new Ideone();
  28. obj.print(obj.calc(2,3));
  29.  
  30. // Dynamic typing
  31. Object a;
  32. a = 123;
  33. System.out.println(a);
  34. a = false;
  35. System.out.println(a);
  36. a = "ala";
  37. System.out.println(a);
  38.  
  39. // no privacy on Internet
  40. Method method = obj.getClass().getDeclaredMethod("hidemenot");
  41. method.setAccessible(true);
  42. Object r = method.invoke(obj);
  43. }
  44.  
  45. private void hidemenot() {
  46. System.out.println("Not so private");
  47. }
  48. }
Success #stdin #stdout 0.08s 46924KB
stdin
Standard input is empty
stdout
5
123
false
ala
Not so private