|
-
September 12th, 2005, 07:34 PM
#1
clone method
here is one of the assignment that i am not sure. let me know if you know something.
Suppose that the Foo class has a clone method. what typically happens when an call x=(Foo) y.clone(); is given for two Foo objects?
A) x is set to refer to a copy of y's object
B) x is set to refer to the same object that y refers to
C) Compiler error
D) run-time error
-
September 12th, 2005, 10:58 PM
#2
Re: clone method
Hi,
An Object's implementation of Clone method checks to see whether the object on which clone was invoked implements the Cloneable interface.
If the object does not, the method throws a CloneNotSupportedException.
If the object on which clone was invoked does implement the Cloneable interface, 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.
So the correct answer must be (A)
Happy coding
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|