This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Mock Exam Errata and the fly likes Cameron's SCJA Mock Exam Question (pg.200, 9-4) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Mock Exam Errata
Reply Bookmark "Cameron Watch "Cameron New topic
Author

Cameron's SCJA Mock Exam Question (pg.200, 9-4)

Rob Poulos
Ranch Hand

Joined: Aug 21, 2009
Posts: 49
Here is the question:

Given the following code snippet, What would be valid lines of code to replace the comment "//line xxx"?


potential aswers (choose 1):

According to the book, the correct answer is A and it explains that the other answers will compile but will trigger a runtime exception.

now. I tried this in Eclipse and found the following:


this results in a "Exception in thread "main" java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.Double" error

this results in the code successfully compiling and running; printing 10.1 to the system.out

this results in the code successfully compiling and running; printing 10.1 to the system.out

this results in a "Exception in thread "main" java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.Integer" error

This being said, i would think both B and C would be the only valid answers. Or am i missing something?


SCJA, ITIL V3 Foudation, Studying for SCJP6
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Cameron's SCJA Mock Exam Question (pg.200, 9-4)
 
Similar Threads
Using java.util.Vector
Sorting elements Comparator or Collection
Autoboxing feature
help in fixing the error
Sorting a Vector by variable in the Object