• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!