Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

John Hunt's Mock Exam: Q61

 
Jim Crawford
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Jim Crawford
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Else" should be "else".
I can comlile it and output is "Hello".
"if(a = true)" is always true.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic