• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

clone methode

 
omar bili
Ranch Hand
Posts: 177
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
omar bili
Ranch Hand
Posts: 177
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic