Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

anilbachi's mock

 
Dinesh Kumar
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • 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?
 
Lionel Port
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • 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).
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
suresh kamsa
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I go to anilbachi mock exam site? If you have please send me the link.
Thanks
 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • 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 ]
 
Jeremy Hynoski
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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!
 
Shishio San
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic