Welcome Guest | Sign in | Register
Operators and Assignments - Discussion Page For Q.2927 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Operators and Assignments > Questions and Answers

Exercise:

Section 1

Q: 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?

1. f1 == f2
2. f1 == f3
3. f2 == f1[1]
4. x == f1[0]
5. f == f1[0]
A. 1, 2 and 3 B. 2, 4 and 5
C. 3, 4 and 5 D. 1, 4 and 5

Answer and Explanation

Answer:2, 4 and 5

Explanation:
(2) is correct because the reference variables f1 and f3 refer to the same array object.
(4) is correct because it is legal to compare integer and floating-point types.
(5) is correct because it is legal to compare a variable with an array element.
(3) is incorrect because f2 is an array object and f1[1] is an array element.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.