JavaTip : Basic cloning example code in java

package com.premseem.cloning;

import java.util.Date;

public class CloningMain {

    public static void main(String[] args) throws CloneNotSupportedException {
        Employee empBreeder = new Employee(“aseem” , “Jain”);
        Employee empClone1 = (Employee) empBreeder.clone();
        Employee empClone2 = (Employee) empBreeder.clone();

class Employee implements Cloneable{
    public Employee(String name, String surName){ = name;
        this.surname = surName;
    String name;
    String surname;
    Date date = new Date();
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    public String toString() {
        return name + ” ” + surname + ” ” + date +” ” + hashCode();


Clone (κλών) is a Greek word meaning “branch”, referring to the process whereby a new plant can be created from a twig. In biology it is about copying the DNAs.In java, though clone is ‘intended’ to produce a copy of the same object it is not guaranteed. Clone comes with lots of its and buts.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s