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

anilbachi's mock

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Here are three q's from anilbachi's site on Language Fundamentals. The answers as given on the site are as indicated next to each question. I think all these answers are incorrect:
Q16: Which of the following is not a valid top level class?
a). public class topclass
b). static class topclass
c). private class topclass
d). all the above
e). a and b

Ans. e
Correct ans. should be: c
Q17: An example unicode value is '0x3c0' in hexadecimal.
Which of the following correctly initializes the char primitive to the
pi?
a). char pi='u3c0';
b). char pi='\u03c0';
c). char pi="\u03c0";
d). char pi='\x03c0';

Ans. a
Correct should be: b
Q23: Choose the correct applicable statement for the following code
fragment
1.String countries[];
2.countries[0]="india";
a]. no error occurs
b]. compile time error occurs because the countries array object has
not been created
c]. runtime error occurs because the countries array object has not
been created

Ans. c
Correct should be b.
Am I right?
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Q16: Which of the following is not a valid top level class?
a). public class topclass
b). static class topclass
c). private class topclass
d). all the above
e). a and b

Ans. e
Correct ans. should be: c


I would go even further and say that the answer should be (b) and (c).
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The given answer to Q23 is correct. You will get a NullPointerException at runtime because "countries" starts out as a null reference.
 
Dinesh Kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm yes,
Well, it shows me the exception if the String object is declared as a class member, but if I have both these statements inside a method, then it shows "variable may not have been initialized"
at compile time.
Therefore, I would call it an ambiguous question.
Thanks.
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I go to anilbachi mock exam site? If you have please send me the link.
Thanks
 
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Denish:


Well, it shows me the exception if the String object is declared as a class member, but if I have both these statements inside a method, then it shows "variable may not have been initialized"
at compile time.


Are you also creating the object from within method? I think Ron is correct!!
[ September 16, 2002: Message edited by: Barkat Mardhani ]
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that the answer on the test is wrong unless the array is declared as a member variable, as only member variables (and array references) are automatically initialised to null.
Thus it is an ambiguous question, as the fragment depends heavily on context!
 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,
Why is it that the compiler doesn't complain about countries[0]="india" when it's decraled as an instance variable and does complain only when it's a local variable. ??? Can anyone say ?
Thx in advance.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's a local variable, then
String countries[];
is uninitialized. If you don't assign something to it before indexing it, the compiler will complain.
If it's an instance or static variable, the compiler will initialize it to null. A later attempt to assign to countries[0] will cause a NullPointerException.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic