| Author |
"==" Question from Kathy's Book
|
May-Yoong Cheah
Greenhorn
Joined: Apr 02, 2003
Posts: 8
|
|
Given the following, import java.awt.Button; class CompareReference { public static void main (String [] args){ float f = 42.0f; float [] f1 = new float[2]; float [] f2 = new float[2]; float [] f3 = f1; long x = 42; f1[0] = 42.0f; } } which three statements are true? (Choose three) A. f1 == f2 B. f1 == f3 C. f2 == f1[1] D. x == f1[0] E. f == f1[0] The answers are B,D and E. The question is why D, that is why you are allow to compare a long with a float?
|
 |
preeti khane
Ranch Hand
Joined: Mar 12, 2003
Posts: 93
|
|
|
because of automatic numeric promotion , a long is promoted to a float and the comparison works out to true
|
 |
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
|
|
Preeti is right. In this case, we have what is known as binary numeric promotion. You can read all about it in the JLS, sect;5.6.2 Binary Numeric Promotion. Corey
|
SCJP Tipline, etc.
|
 |
 |
|
|
subject: "==" Question from Kathy's Book
|
|
|