Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Clarification needed on Exam Prep question  RSS feed

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are correct. goto is a reserved word that is not currently being used, and friend is not a reserved word.
Bill
 
Pratap Reddy
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
*****************
 
Pratap Reddy
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you vadiraj. Sure next time I will post the questions in
threads.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!