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
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).
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.
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 ]
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!
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
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.
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut: