jQuery in Action, 3rd edition
The moose likes Mock Exam Errata and the fly likes John Hunt's Mock Exam: Q61 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "John Hunt Watch "John Hunt New topic

John Hunt's Mock Exam: Q61

Jim Crawford
Ranch Hand

Joined: Sep 08, 2002
Posts: 127

Q. 61
Consider the following program:

What is the result:
A. Program produces no output but terminates correctly.
B. Program does not terminate.
C. Prints out "Hello"
D. Prints out "Goodbye"
Select the most appropriate answer.

This code will not compile, and the suggested answer is C.

PS. I see this forum is not really used. If I don't get a reply I'll post in SCJP forum.

<img src="cool.gif" border="0"> <img src="graemlins/beerchug.gif" border="0" alt="[beerchug]" /> <br />SCJP 1.4
Jim Crawford
Ranch Hand

Joined: Sep 08, 2002
Posts: 127
Guess the fact that its wrong is a given. Pity this forum is not up to date.
Thought I'd find all wrong mock answers here.
Maurice Hou

Joined: Sep 19, 2002
Posts: 2
"Else" should be "else".
I can comlile it and output is "Hello".
"if(a = true)" is always true.
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
Jim, as limoki said, the only mistake I can see here is a typo on "Else" which should read "else" instead, but that's all. The code is otherwise correct and the correct answer is C.
Pay special attention to statements like
if(a = true)
which is not the same as
if(a == true)
In the former, the condition will always be true since the boolean variable a is assigned true anf the whole expression evaluates to a's value, that is true.
Welcome to Javaranch
We'd like you to read the Javaranch Naming Policy and change your publicly displayed name (change it here) to comply with our unique rule. Thank you.
PS: Quote from the naming policy:

For your publicly displayed name, use a first name, a space, and a last name. Obviously fictitious names or improperly formatted names may be locked out.

[ September 19, 2002: Message edited by: Valentin Crettaz ]

[Blog] [Blogroll] [My Reviews] My Linked In
I agree. Here's the link: http://aspose.com/file-tools
subject: John Hunt's Mock Exam: Q61
It's not a secret anymore!