Which of the following is not a reserved word in Java? (a) import (b) finally (c) friend (d) goto Answer is (d) , But according to my knowledge right answer is (c)
If I declare String[] name = new String[10]; , then my question is name[0] is object of String. Correct me If I am wrong. if(name[0] instanceof String) print "True" else print "False"; I was expecting "True" but printed "False"; Can any one clarify?.
Hi Pratap, Nice question, 1)The instanceof operator only checks the instances of object references. 2)All the arrays will always be initialised to their default values. So refering to the above facts, your array of strings contains 10 object references to 10 string objects but currently they are pointing to nowhere i.e. to [B] null [/B}. So the answer is false as null cannot be a instance of any Class. If you assign a value to name[0] then it gives true. Please check out the code below. CODE ---------
<pre> public class StringArrayTest { public static void main(String a[]) { String s[] = new String[10]; s[0] = "He;"; if( s[0] instanceof String) System.out.println("True"); else System.out.println("False"); } } </pre>
---------- END OF CODE Hope this helps. Also please post the questions in different threads so that they can be viewed differently.
------------------ Regards --------- vadiraj
***************** There's a lot of I in J. *****************
Regards<BR>---------<BR>vadiraj<P><BR>*****************<BR>There's a lot of I in J.<BR>*****************