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) |
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(); } }
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()); } }
Original book Object ... Name = Children Story ISBN Number = 2000 ---------------------------- Cloned book Object ... Name = Children Story ISBN Number = 2000
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:
No comments:
Post a Comment