Bird
0
0

In Kotlin, when you write val x = 10, what type does the compiler infer for x?

easy📝 Conceptual Q1 of 15
Kotlin - Variables and Type System
In Kotlin, when you write val x = 10, what type does the compiler infer for x?
ADouble
BString
CAny
DInt
Step-by-Step Solution
Solution:
  1. Step 1: Identify the assigned value type

    The value assigned to x is 10, which is a whole number.
  2. Step 2: Understand Kotlin's type inference

    Kotlin infers the type based on the assigned value. Whole numbers without decimals are inferred as Int.
  3. Final Answer:

    Int -> Option D
  4. Quick Check:

    Type inference = Int [OK]
Quick Trick: Whole numbers default to Int type in Kotlin [OK]
Common Mistakes:
MISTAKES
  • Thinking 10 is Double because it is a number
  • Assuming default type is Any
  • Confusing Int with String

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes