Bird
0
0

What will be the output of this code?

medium📝 Predict Output Q5 of 15
Java - Wrapper Classes
What will be the output of this code?
Double d = 4.5;
double result = d * 2;
System.out.println(result);
ACompilation error
B4.5 2
C9.0
D8.5
Step-by-Step Solution
Solution:
  1. Step 1: Recognize unboxing in multiplication

    Double d is unboxed to double primitive for multiplication.
  2. Step 2: Calculate the multiplication

    4.5 * 2 = 9.0, so result is 9.0 printed.
  3. Final Answer:

    9.0 -> Option C
  4. Quick Check:

    Unboxing allows Double in arithmetic operations [OK]
Quick Trick: Wrapper objects unbox automatically in math expressions [OK]
Common Mistakes:
  • Expecting string concatenation output
  • Confusing double and Double types
  • Thinking explicit cast is needed

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes