File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes anilbachi's mock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "anilbachi Watch "anilbachi New topic
Author

anilbachi's mock

Dinesh Kumar
Ranch Hand

Joined: Jul 03, 2002
Posts: 54
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

Joined: Sep 14, 2002
Posts: 19
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

Joined: Jun 06, 2002
Posts: 1056
The given answer to Q23 is correct. You will get a NullPointerException at runtime because "countries" starts out as a null reference.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Dinesh Kumar
Ranch Hand

Joined: Jul 03, 2002
Posts: 54
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

Joined: Jul 30, 2001
Posts: 149
How do I go to anilbachi mock exam site? If you have please send me the link.
Thanks
Barkat Mardhani
Ranch Hand

Joined: Aug 05, 2002
Posts: 787
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

Joined: Sep 17, 2002
Posts: 4
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

Joined: Aug 29, 2002
Posts: 223
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.


Whatever doesn't kill us ...<br />Is probably circling back for another try.<br />SCJP 1.4
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
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.
 
 
subject: anilbachi's mock