File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes clone methode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "clone methode" Watch "clone methode" New topic
Author

clone methode

omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
Hi
the clone method: what does it do?
is it another reference to the same class, if yes how can i really
clone an object, so i can have 2 different objects?
Best
Avisesh Jain
Greenhorn

Joined: Mar 16, 2005
Posts: 12
Check out his link for more details on clone method.

http://java.sun.com/docs/books/tutorial/java/javaOO/objectclass.html
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by omar bili:
Hi
the clone method: what does it do?
is it another reference to the same class, if yes how can i really
clone an object, so i can have 2 different objects?
Best

In Java, we don't have references to classes. We have references to objects (instances of classes) instead. The clone() method returns a new reference to a new object (a clone). However, there are some details that are discussed in the web page given by Avisesh's link above. I'll let you read that before I go on.

Please come back with more questions if you run into problems.

Layne


Java API Documentation
The Java Tutorial
omar bili
Ranch Hand

Joined: Aug 13, 2004
Posts: 177
Hi,
What i need to know, if i clone an instance of a class

Box b = new Box() ;

b.height = 100 ;

Box a = b.clone() ;
a.height = 200 ;

here b.height = ?? is it 100 or 200

a and b refer to the same istance, any changes in a will be
applied to b, or a and b are totally different instances, in
the memory?
Kind regards, Bili
Avisesh Jain
Greenhorn

Joined: Mar 16, 2005
Posts: 12
"Object's implementation of the clone method creates an object of the same type as the original object and initializes the new object's member variables to have the same values as the original object's corresponding member variables"

I hope this will clear your doubts.
[ March 22, 2005: Message edited by: Avisesh Jain ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: clone methode