Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Homework HelpRSS Feeds

Program to show an example of Copying i.e. Clonning Objects

Posted By: Aazad Hashmi     Category: Java     Views: 1598

A Java Program to show an example of Copying i.e. Clonning Objects.

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);
       }
    }
 }
  
Share: 



Aazad Hashmi
Aazad Hashmi author of Program to show an example of Copying i.e. Clonning Objects is from Hyderabad, Pakistan.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!