Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam 1z0-808 topic 1 question 117 discussion

Actual exam question from Oracle's 1z0-808
Question #: 117
Topic #: 1
[All 1z0-808 Questions]

Given the code fragment:

What is the result?

  • A. An exception is thrown at runtime.
  • B. Compilation fails.
  • C. 13480.0
  • D. 13480.02
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
EmilioDeBaku
Highly Voted 2 years, 10 months ago
Answer is C
upvoted 6 times
...
amit_lad88
Most Recent 4 months, 2 weeks ago
Selected Answer: D
Correct Answer is D float var1 = (12_345.01 <= 123_45.00) ? 12_456 : 124_56.02f; // 124_56.02f value assigned to var1 float var2 = var1 + 1024; // 124_56.02f +1024 System.out.println(var2); // 13480.02
upvoted 1 times
...
ManuTov
6 months, 3 weeks ago
Indeed, the key aspect here is the return type of the ternary expression, which is determined by the possible types of the operands. In this case, even though the boolean expression involves doubles, the ternary operator considers the common type compatible with both branches, which is float because float can accommodate both 12_456 and 12456.02f. This is why the result is float and not double.
upvoted 1 times
...
RAADEL3IMLAK
1 year, 2 months ago
Answer is D. is tested
upvoted 3 times
...
carloswork
1 year, 5 months ago
Selected Answer: D
Answer is D. To test: public static void main(String[] args) { float var1 = (12_345.01 <= 123_45.00) ? 12_456 : 124_56.02f; float var2 = var1 + 1024; System.out.println(var2); }
upvoted 2 times
...
UAK94
1 year, 6 months ago
Answer is D. float var1 = (12_345.01 <= 123_45.00) ? 12_456 : 124_56.02f; float var2 = var1 + 1024; System.out.println(var2); // 13480.02
upvoted 2 times
...
iSnover
1 year, 6 months ago
Selected Answer: D
The answer is the letter D, analyzing the expression, it returns a false, so it returns 124_56.02f (remembering that the _ does not separate the decimal place, it only separates the number, it only serves to help reading) so when adding 12456.02 + 1024 = 13480.02
upvoted 1 times
...
Aysegul
2 years, 10 months ago
B, if returns true so double comes. Then it couldn’t be assigned float
upvoted 2 times
Winston123
1 year, 11 months ago
int value can assign to the float value
upvoted 1 times
...
JongHwa
2 years, 5 months ago
12_456 is not double but int.
upvoted 2 times
...
...
SSJ5
3 years, 1 month ago
Correct answer C
upvoted 2 times
...
P_Riya
3 years, 3 months ago
The correct answer C, Tested 13480.0
upvoted 2 times
...
alain001
3 years, 6 months ago
float var1 = (12_345.01 >= 123_45.00) ? 12_456 : 124_56.02f; float var2 = var1 + 1024; System.out.println(var2);
upvoted 1 times
...
babobobina
3 years, 6 months ago
Correct answer : C - 13480.0 float var1; if(12_345.01 >= 123_45.00){ var1 = 12_456; }else{ var1=124_56.02f } => the condition is true : 12345.01 > 12345.00 => var1 = 12_456 which means 12456 (The underscore is useful just for the readability). Then var 2 = var1 + 1024; => var 2 = 13480 => Output: 13480.0.
upvoted 1 times
...
kob4yashi
3 years, 7 months ago
tested. correct id D. but still can't say why
upvoted 1 times
...
Harid
3 years, 8 months ago
this is a tricky question. the boolean statement is double and double doesn't fit inside the float. Looks like false/true return type matters here, not data type inside the boolean expression.
upvoted 2 times
...
hotuya
3 years, 8 months ago
The answer is C Confirmed on Netbeans
upvoted 2 times
...
sai9999
3 years, 9 months ago
Correct answer is C
upvoted 2 times
...
kh_ism
3 years, 9 months ago
Tested Correct answer is D : 13480.02
upvoted 3 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...