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!!!
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
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
Post by:autobot
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
a bit of art, as a gift, that will fit in a stocking