Code for Program to show an example of Copying i.e. Clonning Objects in Java
publicclass JAVA_080
{
publicstaticvoid main(String[] args)
{
try
{
PetDog myPet=new PetDog("Fang","Chihuahua");
PetDog yourPet=(PetDog)myPet.clone( );
yourPet.setName("Gnasher");
yourPet.getFlea( ).setName("Atlas");
System.out.println("\nYour Pet Details :\n" + yourPet);
System.out.println("\nMy Pet Details :\n" + myPet);
}
catch(CloneNotSupportedException exp)
{
System.out.println(exp);
}
}
}