About Question com.enthuware.ets.scjp.v6.2.340 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
devlam
Posts: 50
Joined: Sun Nov 10, 2013 4:39 am
Contact:

About Question com.enthuware.ets.scjp.v6.2.340 :

Post by devlam »

In the case of i == f, value of i will be promoted to a float i.e. 5.0, and so it returns false.

What is the rule behind this?
Why is f not converted to an int?

admin
Site Admin
Posts: 10388
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.340 :

Post by admin »

The rule is explained in Section 15.21.1. "Numerical Equality Operators == and !=", which refers to Section 5.6.2.
"Binary Numeric Promotion" of Java Language Specification. To quote -
Otherwise, if either operand is of type float, the other is converted to float.
You might want to go through the above referred sections for full details. Here is the link http://docs.oracle.com/javase/specs/jls ... ls-15.21.1

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests