Single choice question has multiple answers
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi guys,
I got the following code from Whizlab,
which of the following statements is/are true about compiling and running the following code ?
[A] The program comiples correctly and prints "false" and null.
[B] The program will comiple correctly if line 1 is removed
[C] The program will compile correctly if line 2 is removed
[D] The program will compile correctly if line 3 is removed
[E] The program will compile correctly if line 4 is removed
[F] None of above
This test about final reference variable can not assign value more than once. So answer B and E are both correct, but this is a single answer question, which one should I go if similar question appears in real exam?
I got the following code from Whizlab,
which of the following statements is/are true about compiling and running the following code ?
[A] The program comiples correctly and prints "false" and null.
[B] The program will comiple correctly if line 1 is removed
[C] The program will compile correctly if line 2 is removed
[D] The program will compile correctly if line 3 is removed
[E] The program will compile correctly if line 4 is removed
[F] None of above
This test about final reference variable can not assign value more than once. So answer B and E are both correct, but this is a single answer question, which one should I go if similar question appears in real exam?
SCJP 5.0
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Looks like the question is designed with careless attitude. If we go by the compiler then the error will be shown at line 4. So you can go for that.
In exam I don't think that there will be questions like this.
In exam I don't think that there will be questions like this.
My Blog SCJP 5 SCWCD 5
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Only E is the correct answer. Line 1 is OK as it sets the final field for the first time which is allowed...
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
posted 17 years ago
Only E is correct. B is incorrect.
Have you tried to compile the code after line 1 is removed?
It will still not compile. Because line2 is checking instanceof obj, and compiler will give error:
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
This test about final reference variable can not assign value more than once. So answer B and E are both correct
Only E is correct. B is incorrect.
Have you tried to compile the code after line 1 is removed?
It will still not compile. Because line2 is checking instanceof obj, and compiler will give error:
-Varun -
(My Blog) - Online Certifications - Webner Solutions
Henry Zhi Lin
Ranch Hand
Posts: 69
posted 17 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Varun,
you are right, as you said the answer is E and once I removed line one the initialization problem comes out. Thanks to point out
you are right, as you said the answer is E and once I removed line one the initialization problem comes out. Thanks to point out
SCJP 5.0
| crispy bacon. crispy tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |











