This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "John Hunt Watch "John Hunt New topic
Author

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
Greenhorn

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
Sheriff

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.
limoki,
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 ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: John Hunt's Mock Exam: Q61
 
Similar Threads
lowdown on If?
John Hunt mock test
general
quibbling...
If statement with semicolon