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. private static class OBJ {
  11. int one;
  12. String two;
  13.  
  14. public OBJ() {
  15. this.one = 1;
  16. this.two = "two";
  17. }
  18. }
  19.  
  20. public static void test1(OBJ o) {
  21. o.one = 2;
  22. }
  23.  
  24. public static void test2(OBJ o) {
  25. o = new OBJ();
  26. o.two = "no reference";
  27. }
  28.  
  29. public static void main (String[] args) throws java.lang.Exception
  30. {
  31. OBJ x = new OBJ();
  32. test1(x);
  33. test2(x);
  34.  
  35. System.out.println("x.one: " + x.one + " x.two: " + x.two);
  36. }
  37. }
Success #stdin #stdout 0.09s 320576KB
stdin
Standard input is empty
stdout
x.one: 2 x.two: two