• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

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.
 
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic