• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Clarification needed on Exam Prep question

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you vadiraj. Sure next time I will post the questions in
threads.
 
Beauty is in the eye of the tiny ad.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic