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 Base {
  8. private final String name;
  9. public String getName() {return name;}
  10. public Base(String name) {
  11. this.name = name;
  12. }
  13. public Base(Base b) {
  14. this(b.getName());
  15. }
  16. }
  17.  
  18. class Derived extends Base {
  19. public String getName() {
  20. return "["+super.getName()+"]";
  21. }
  22. public Derived(String name) {
  23. super(name);
  24. }
  25. public Derived(Derived d) {
  26. this(d.getName());
  27. }
  28. }
  29.  
  30. /* Name of the class has to be "Main" only if the class is public. */
  31. class Ideone
  32. {
  33. public static void main (String[] args) throws java.lang.Exception {
  34. Derived orig = new Derived("hello");
  35. Derived copy = new Derived(orig);
  36. System.out.println(orig.getName());
  37. System.out.println(copy.getName());
  38. }
  39. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
[hello]
[[hello]]