aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A question on K&B question, expecting reply from Bert Bates himself... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "A question on K&B question, expecting reply from Bert Bates himself..." Watch "A question on K&B question, expecting reply from Bert Bates himself..." New topic
Author

A question on K&B question, expecting reply from Bert Bates himself...

Pad Ven
Ranch Hand

Joined: Apr 29, 2005
Posts: 38
Hi,
For the following question:

Given:
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. }
What is the result?
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.



though I realized that the problem was a missing semicolon in line 7, I could not make out which of the choices and I ultimately made the wrong choice of B although I knew pretty well that it can't be. But I could never imagine the answer would be G. My understanding was compiler can throw error in a line after the erroneous line but never before. What is the real cause of my mistake? Is it my lack of understanding of Java compilation or Java language fundamentals or something else? Or is it that K&B questions are like this only (a little cryptic than actual exam questions)? Or can I expect these kind of questions in the exam? I am worried, since though I got the basics right, I haven't been able to choose the right answer and will not get the marks. Bert Bates, can you guide me in this case?

TVP
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Yes, let's wait for Bert to respond. It's possible he's away for a few days, so be patient...

So if any body else knows what the problem is, we can discuss it later (when Bert gets back).


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ivan Rebrov
Ranch Hand

Joined: Jul 09, 2006
Posts: 30
I'm not Bert, but couldn't help myself to test this code.
Compiler says, that error is in line "7", so the answer "G" is quite correct.

What's your problem?


SCJP 5.0 - 95%<br />Preparing for SCWCD
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8829
    
    5
Hi TV,

it seems that this question is more about the wording of the question rather than the question itself. as a bit of background, we try to match the style and wording of our mock questions as closely as possible to the real exam questions. the only place where we knowingly differ is that we sometimes say "choose all that apply" and on the real exam you will always know exactly how many answers are correct. so...

the exam creation team uses the wording "due to an error on line x". you'll definitely see that wording several times on the real exam - the reason is that it's not possible to know what a particular compiler might say, but it is possible for you to know where the code has a problem.

does that help?

bert


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A question on K&B question, expecting reply from Bert Bates himself...