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. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Foo x = new Foo(123, 456);
  13. System.out.println(x);
  14. Object clone = x.clone();
  15. System.out.println(clone);
  16. }
  17. }
  18.  
  19. class Foo implements Cloneable {
  20.  
  21. private Integer notInClone;
  22. private Integer doClone = 123;
  23.  
  24. public Foo(int a, int b) {
  25. notInClone = a;
  26. doClone = b;
  27. }
  28.  
  29. public Object clone() throws CloneNotSupportedException {
  30. Foo res = (Foo)super.clone();
  31. res.notInClone = null;
  32. return res;
  33. }
  34.  
  35. public String toString() {
  36. return notInClone + ":" + doClone;
  37. }
  38.  
  39. }
Success #stdin #stdout 0.09s 27756KB
stdin
Standard input is empty
stdout
123:456
null:456