aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes need your help about a cast about cloneable.!!!(jcjp07-Q119) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "need your help about a cast about cloneable.!!!(jcjp07-Q119)" Watch "need your help about a cast about cloneable.!!!(jcjp07-Q119)" New topic
Author

need your help about a cast about cloneable.!!!(jcjp07-Q119)

Gong James
Ranch Hand

Joined: Oct 15, 2001
Posts: 77
Q119 Which of the following are true?
A A reference to an array can be cast to a reference to an Object.
B A reference to an array can be cast to a reference to a Cloneable.
C A reference to an array can be cast to a reference to a String.
D None of the above.

the given ans is:A,B.
My ans is:A.
Am I correct ?If not ,correct me Pls!!
You are always to the item!!!
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Originally posted by Gong James:
Q119 Which of the following are true?
A A reference to an array can be cast to a reference to an Object.
B A reference to an array can be cast to a reference to a Cloneable.
C A reference to an array can be cast to a reference to a String.
D None of the above.

the given ans is:A,B.
My ans is:A.
Am I correct ?If not ,correct me Pls!!
You are always to the item!!!

Ans: A,B
How its becoz Every array implements the interfaces Cloneable and java.io.Serializable.
class Test {
public static void main(String[] args) {
int ia1[] = { 1, 2 };
int ia2[] = (int[])ia1.clone();
System.out.print((ia1 == ia2) + " ");
ia1[1]++;
System.out.println(ia2[1]);
}
}
Pls refer JLS for further expln
Enjoy
Ragu
Rashmi Hosalli
Ranch Hand

Joined: Jun 25, 2001
Posts: 50
Hi Ragu,
Shouldn't ia1.equals(ia2) in your example code give true?
Rashmi
Ragu Sivaraman
Ranch Hand

Joined: Jul 20, 2001
Posts: 464
Rashmi
I believe clone() makes a shallow copy not a deep one
Ragu
Gong James
Ranch Hand

Joined: Oct 15, 2001
Posts: 77
You meant that java.lang.reflect.array is subclass of the interface java.lang.cloneable.

But i cant find the description in the jdk_doc(v1.3).
Where the conclusion "array class implements interface cloneable" comes from?
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9053
    
  12
Read this about arrays in the JLS http://java.sun.com/docs/books/jls/second_edition/html/arrays.doc.html#61637


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jim Petersen
Ranch Hand

Joined: Jul 24, 2001
Posts: 241
Originally posted by Gong James:
You meant that java.lang.reflect.array is subclass of the interface java.lang.cloneable.
But i cant find the description in the jdk_doc(v1.3).
Where the conclusion "array class implements interface cloneable" comes from?

Hi Gong:
Hope this clears up the confusion... java.lang.reflect.array inherits (is a subclass of) from java.lang.Object, and directly inherits the clone() method from java.lang.Object which to quote the API states:
The method clone for class Object performs a specific cloning operation. First, if the class of this object does not implement the interface Cloneable, then a CloneNotSupportedException is thrown. Note that all arrays are considered to implement the interface Cloneable. Otherwise, this method creates a new instance of the class of this object and initializes all its fields with exactly the contents of the corresponding fields of this object, as if by assignment; the contents of the fields are not themselves cloned. Thus, this method performs a "shallow copy" of this object, not a "deep copy" operation.
- all the best Jim


- Jim Petersen <br />SCJP2<br />SCWCD<p>- but then again, I could be wrong...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need your help about a cast about cloneable.!!!(jcjp07-Q119)