Which of the following Kotlin variable declarations uses type inference correctly?
easy📝 Syntax Q12 of 15
Kotlin - Variables and Type System
Which of the following Kotlin variable declarations uses type inference correctly?
Aval number: String = 10
Bval number: Int = "10"
Cval number = 10
Dval number =
Step-by-Step Solution
Solution:
Step 1: Check each declaration for correctness
val number = 10 assigns 10 to 'number' without specifying type, so compiler infers Int type correctly.
Step 2: Identify errors in other options
val number: Int = "10" assigns a String to Int type explicitly - error. val number: String = 10 assigns Int to String type - error. val number = is incomplete syntax.
Final Answer:
val number = 10 -> Option C
Quick Check:
Correct syntax with inferred type = val number = 10 [OK]
Quick Trick:Look for variable with value but no explicit type [OK]
Common Mistakes:
MISTAKES
Mixing types in assignment
Leaving declaration incomplete
Assigning wrong type to explicit type
Master "Variables and Type System" in Kotlin
9 interactive learning modes - each teaches the same concept differently