The Object class provides a clone() method, which returns a copy of the current object. : clone method « Utility Classes « SCJP






public class MainClass {
  public static void main(String[] argv) {
    MyClass my = new MyClass();
    System.out.println(my.toString());
  }
}

class MyClass {

  public Object clone() throws CloneNotSupportedException {
    return super.clone();
  }

}








8.5.clone method
8.5.1.The Object class provides a clone() method, which returns a copy of the current object.