Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q5 of 15
Kotlin - Data Types
What will be the output of this Kotlin code?
val a: Float = 1.5f
val b: Double = 2.5
val c = a + b
ACompilation error due to type mismatch
B4.0
C4.0f
D4.0d
Step-by-Step Solution
Solution:
  1. Step 1: Identify types in the expression

    a is Float, b is Double. Kotlin does not implicitly convert Float to Double in arithmetic.
  2. Step 2: Check if implicit conversion occurs

    Adding Float and Double without explicit conversion causes a compilation error.
  3. Final Answer:

    Compilation error due to type mismatch -> Option A
  4. Quick Check:

    Float + Double without conversion = error [OK]
Quick Trick: Float and Double must be explicitly converted before arithmetic [OK]
Common Mistakes:
MISTAKES
  • Assuming Float auto converts to Double
  • Expecting Double result without conversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes