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.  
  11. public static class Base {
  12.  
  13. public Base() {
  14. // dangerous virtual call
  15. foo();
  16. }
  17.  
  18. public void foo() {}
  19.  
  20. }
  21.  
  22. public static class Child extends Base {
  23.  
  24. private final int val;
  25.  
  26. public Child(int val) {
  27. this.val = val;
  28. }
  29.  
  30. @Override
  31. public void foo() {
  32. // val should always be initialized here. Or not?
  33. System.out.println("Val is " + val);
  34. }
  35. }
  36.  
  37. public static void main (String[] args) throws java.lang.Exception
  38. {
  39. Child c = new Child(25);
  40. }
  41. }
Success #stdin #stdout 0.08s 380160KB
stdin
Standard input is empty
stdout
Val is 0