Bird
0
0

Which of the following Kotlin variable declarations has a syntax error due to explicit type declaration?

easy📝 Syntax Q3 of 15
Kotlin - Variables and Type System
Which of the following Kotlin variable declarations has a syntax error due to explicit type declaration?
Avar age Int = 30
Bvar name: String = "Alice"
Cval isActive: Boolean = true
Dval count: Int = 5
Step-by-Step Solution
Solution:
  1. Step 1: Review correct syntax for explicit type declaration

    The correct syntax is var variableName: Type = value, with a colon before the type.
  2. Step 2: Identify the syntax error

    var age Int = 30 misses the colon between age and Int, causing a syntax error.
  3. Final Answer:

    var age Int = 30 -> Option A
  4. Quick Check:

    Explicit type syntax requires colon between name and type [OK]
Quick Trick: Always put ':' between variable name and type [OK]
Common Mistakes:
MISTAKES
  • Omitting colon between variable name and type
  • Using wrong assignment operator
  • Missing quotes for string values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes