fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import static java.lang.System.out;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. static class Base {
  12. int i;
  13. }
  14.  
  15. static class Derived extends Base {
  16. int i;
  17. }
  18.  
  19.  
  20. public static void main (String[] args) throws java.lang.Exception
  21. {
  22. Derived derived = new Derived();
  23. Base base = derived;
  24. derived.i = 5;
  25. base.i = 6;
  26. out.println(derived.i);
  27. out.println(base.i);
  28. out.println(((Base) derived).i);
  29. ((Base) derived).i = 4;
  30. derived.i = 3;
  31. out.println(derived.i);
  32. out.println(base.i);
  33. out.println(((Base) derived).i);
  34. }
  35. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
5
6
6
3
4
4