• 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

NOTICE to Kathy & Bert: Error in Study Guide Chap 8 Self Test

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following is an example of something I have feared would be on the
SCJP exam and marked incorrect, even though an incorrect answer actually
is the correct one.

SCJP Study Guide by Kathy & Bert, Chap 8 Self Test (Inner Classes) problem 9.



The answer choices are:
A: An exception occurs at runtime
B: true
C: fred
D: Compilation fails because of an error on line 3
E: Compilation fails because of an error on line 4
F: Compilation fails because of an error on line 8
G: Compilation fails because of an error on a line other than 3,4 or 8

The answer given is G, but I believe the correct answer is F:

If you compile this code and run it, the compiler complains about line
8, expecting a ';'.

This is correct!! Just because line 7 closes out the anonymous class with
the '}', doesn't mean the ';' has to be on the same line, or even the
next line. All that needs to happen is that the ';' is the next token that
the compiler sees, even if there are a 100 blank lines after '}' and before
';'. I agree with good programming principles, that the ';' should be
after the '}' on line 7, but the compiler doesn't give a hoot about those
principles.

Thus, by choosing F instead of G, the answer would have been marked wrong
on the exam. And since you don't get to see what questions you missed,
you would not have thought that this answer was marked wrong.

Kathy & Bert, Please either prove me wrong here (Whew!) or what can
be done about this?

Thanks,

-Bruce
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still, I feel the answer should be G, as the error is due to the missing semi-colon after the "}" at line 7.

Although there is no restriction on where to put the semi-colon, obviously that you wont put it at line 8.

Nick
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With the code as listed there is only two places you could put the semi-colon, on line 7 at the end or line 8 at the beginning. As Nicholas said it is not reasonable to put it at the beginning of line 8. So it would go on line 7, giving G as the answer. But there is an ambiguity that should be removed.


Error messages are implemention dependent anyway so some compiler could say something like "this statement is incorrectly terminated" pointing to line 3.
[ December 08, 2004: Message edited by: Barry Gaunt ]
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Bruce -

First off, thanks for the catch, it turns out we already new about this one, and it'll be fixed in the next edition!

Second, the language in the question is a bit ambiguous, but Sun made sure that on the real exam you won't encounter ant such abmibuous language... I'd say you've got this bit of knowledge nailed down tight

- Bert
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
code:

1: public class TestObj {
2: public static void main(String[] args) {
3: Object o = new Object() {
4: public boolean equals(Object obj) {
5: return true;
6: }
7: }
8: System.out.println(o.equals("Fred"));9: }10:}

--------------------------

First thing I would like to point out is that the when we compile the above source code the error is reported on line 7, not on line 8.

Second thing is, I completly agree Bruce that we can put as many white spaces in between to } and ; .
But I feel that there is no confusion because the semicolon is not at all placed after } and before anything else. The compiler starts to search for ; after } and it finds System.out.println statement on line 8 (doesnt matter even if the println is on line 12). Hence the error will be shown on line 7 where the } is placed.

I feel the option F is not at all valid, the only thing which can be chaged (for more clarity) is the way option G is framed .

Bottom line... option G is correct.

Looking forward to hear from you Bert.

Reagards,
Manny
 
Bert Bates
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Warning: I'm about to fall on my sword... again

So, I think we're all agreed that this question (which I wrote), isn't very well worded. I think we also agree that we need a ; somewhere between the } and the SOP. I promise I will write a much better question for the next edition of the book

In the meantime, the key things for you guys who are studying for the 1.4 are:

1 - The questions on the exam will NOT be so poorly worded
2 - Every compiler is different, so we can't guarantee what message "the" compiler will give, and the exam won't ask you what the compiler will say... phewww...
3 - The exam will ask you, unambiguously, what or where the error is!

HTH,

- Bert
 
MannY Gates
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the reply Bert.
Frankly speaking won't use the term "poorly worded" for the option G.... I would rather call it tricky

Regards,
Manny
 
reply
    Bookmark Topic Watch Topic
  • New Topic