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. class A {
  8. int i;
  9. }
  10.  
  11. class B extends A {
  12. int i;
  13. }
  14.  
  15. /* Name of the class has to be "Main" only if the class is public. */
  16. class Ideone
  17. {
  18. public static void main (String[] args) throws java.lang.Exception
  19. {
  20. B b = new B();
  21. A a = b;
  22.  
  23. a.i = 1;
  24. b.i = 2;
  25. System.out.println(a.i);
  26. System.out.println(b.i);
  27. System.out.println("Czy to ten sam obiekt? " +
  28. (a == b ? "Tak." : "Nie."));
  29. }
  30. }
Success #stdin #stdout 0.1s 320512KB
stdin
Standard input is empty
stdout
1
2
Czy to ten sam obiekt? Tak.