This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mock Exam Question

 
Rob Poulos
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.scja.de/scja-mock-exam-section3.html

The Question:



My answer was A,B,C,D as i figured that 'float f=3.5' would still compile but f would be converted to a double as 3.5 was not casted with a F (3.5F)





 
Campbell Ritchie
Sheriff
Posts: 48454
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please tell us where that question comes from.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
f would be converted to a double as 3.5 was not casted with a F (3.5F)


You caught it right that 3.5 without the F is a double value, but how can the datatype of f be converted. We cannot change the type of a variable once it is declared. So that line will not compile as we are trying to assign a double value to a float variable....
 
Campbell Ritchie
Sheriff
Posts: 48454
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for adding the link about where the question was from.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic