Thursday 4 February 2016

Java Tutorial : Java Object Class(clone method)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=bhpEaptLOww&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java Object Class(clone method) 
Java Tutorial : Java Object Class(clone method) 
Java Tutorial : Java Object Class(clone method) 
Book.java
public class Book implements Cloneable
{
    private String name;
    private String isbnNumber;

    public Book(String name, String isbnNumber)
    {
        super();
        this.name = name;
        this.isbnNumber = isbnNumber;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getIsbnNumber()
    {
        return isbnNumber;
    }

    public void setIsbnNumber(String isbnNumber)
    {
        this.isbnNumber = isbnNumber;
    }

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

}
ObjectClassTest.java
public class ObjectClassTest
{

    public static void main(String[] args)
            throws CloneNotSupportedException
    {
        Book childrenStoryBookObj = new Book("Children Story", "2000");
        System.out.println("Original book Object ...");
        System.out.println("Name        = "
                + childrenStoryBookObj.getName());
        
        System.out.println("ISBN Number = "
                + childrenStoryBookObj.getIsbnNumber());

        Book clonedChildrenStoryBookObj = (Book) childrenStoryBookObj
                .clone();

        System.out.println("----------------------------");
        System.out.println("Cloned book Object ...");
        System.out.println("Name        = "
                + clonedChildrenStoryBookObj.getName());
        System.out.println("ISBN Number = "
                + clonedChildrenStoryBookObj.getIsbnNumber());

    }

}
Output
Original book Object ...
Name        = Children Story
ISBN Number = 2000
----------------------------
Cloned book Object ...
Name        = Children Story
ISBN Number = 2000
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/ObjectClassDemo_clone_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/ObjectClassDemo_clone_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/f82b5a337c881ba48c0d1163c2b3b206ee915253/BasicJava/ObjectClassDemo_clone_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment