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. // your code goes here
  13. Test test = new Test("Test");
  14. System.out.println(test.getName());
  15. Test test2 = test.clone();
  16. System.out.println(test2.getName());
  17.  
  18. }
  19. }
  20.  
  21. class Test implements Cloneable {
  22.  
  23. private String name;
  24.  
  25. public Test(String name) {
  26. this.name = name;
  27. }
  28.  
  29. public String getName() {
  30. return this.name;
  31. }
  32.  
  33. public void setName(String name) {
  34. this.name = name;
  35. }
  36.  
  37. public Test clone() throws CloneNotSupportedException {
  38. return (Test) super.clone();
  39. }
  40. }
  41.  
Success #stdin #stdout 0.11s 54576KB
stdin
Standard input is empty
stdout
Test
Test