Rules of Object Reference Conversion (RHE) says ... a) Interface type can only be converted to another interface type or Object class.if it is an interface it must be the super interface. Now how will we test these rules when its not possible to instantiate an interface?
b) Also arrays may be converted to Object, Cloneable and Serializable interfaces? Why these two interfaces? c) Object o = new Sub[5]; This compiles but how'll we access the array members? Thanx Lakshmi
Udayan Naik
Ranch Hand
Joined: Oct 18, 2000
Posts: 135
posted
0
Hi lakshmi.The RHE states that the rules are for Object REFERENCE conversion.This means that u need only a reference to test those rules , and not a object.You need not create an object by instantiation for testing those rules.Also observe the examples given in RHE regarding those rules. All classes are sub-classes of Object.Thus an array can be referenced by an Object reference.Arrays also implement the Cloneable interface which means that calling the clone() method on an array is legal.And Arrays also implement the Serializable interface which means that it is possible to store the array object to persistent storage. Thus array reference can be converted to Object,Cloneable or Serializable references.
------------------ Come on in !! Drinks are on the house in the Big Moose Saloon !!
Udayan Naik<BR>Sun Certified Programmer for the Java 2 Platform
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Iakshmi, For question a), try the read and execute the following application which illustrate the usage of interface and cast between interfaces and Object.
Hope this clarifies, Beno�t [This message has been edited by Beno�t d'Oncieu (edited November 01, 2000).]
lakshmi nair
Ranch Hand
Joined: Oct 11, 2000
Posts: 63
posted
0
That was a great thing, Beno�t. I think i got it. Also Udayan, how'll we know that arrays implement those intefaces. This seem to be stupid but i checked the api before posting the question.I could not find any. Thanks lakshmi
If its green its biology if its stinkks its chemistry if it has numbers it is Maths and if it doesn't work its TECHNOLOGY
Udayan Naik
Ranch Hand
Joined: Oct 18, 2000
Posts: 135
posted
0
Hi Lakshmi.For information regarding an array implementing the Cloneable interface , look up the Object.clone() method. All arrays also implement the Serializable interface.You can verify both these statements as below.
And please , no question is stupid if it is helping you to clear your doubts and passing the Certification Exam. ------------------ Come on in !! Drinks are on the house in the Big Moose Saloon !!