float f = 3.14;
Which of the following assignments is guaranteed to compile without loss of precision?
double d = 3.14f;
int i = 3.14f;
short s = 100000;
byte b = 200;
Show answer & explanationAnswer
Correct answer
double d = 3.14f;
Explanation
A `float` can be assigned to a `double` without explicit cast because `double` has a larger range and precision (widening primitive conversion). The other options involve narrowing conversions that require an explicit cast or may lose information.
Written by ExamHoot EditorialPublished · Updated
All 10 Java-variables and data types questions
- 1.Which of the following declarations correctly initializes a `char` variable with the Unicode value corresponding to the Greek letter omega…
- 2.Consider the following code:
- 3.Which of the following assignments is guaranteed to compile without loss of precision?
- 4.Given:
- 5.What is the output of the following code?
- 6.Which of the following is a valid declaration for a multi-dimensional array of `double` with 3 rows and 4 columns, where all elements are…
- 7.Consider the following:
- 8.What is the range of values that can be stored in a `byte` data type in Java?
- 9.Which of the following statements about the `final` keyword with primitive variables is true?
- 10.Given the following code, what is the value of `result`?
