Bird
0
0

Which of the following Kotlin variable declarations is syntactically correct and uses type inference?

easy📝 Syntax Q3 of 15
Kotlin - Variables and Type System
Which of the following Kotlin variable declarations is syntactically correct and uses type inference?
Aval number: = 5.5
Bval number = 5.5
Cval number 5.5
Dval number == 5.5
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of each declaration

    val number = 5.5 uses correct syntax: val variable = value. Others have syntax errors like misplaced colons or missing equals.
  2. Step 2: Confirm type inference usage

    val number = 5.5 lets Kotlin infer Double type from 5.5, which is valid.
  3. Final Answer:

    val number = 5.5 -> Option B
  4. Quick Check:

    Correct syntax with type inference [OK]
Quick Trick: Use '=' to assign value; no colon needed for inference [OK]
Common Mistakes:
MISTAKES
  • Using ':' without type after variable
  • Missing '=' sign
  • Using '==' instead of '='

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes