Bird
0
0

Which of the following is the correct syntax for explicit type declaration of a variable in Kotlin?

easy📝 Syntax Q12 of 15
Kotlin - Variables and Type System
Which of the following is the correct syntax for explicit type declaration of a variable in Kotlin?
Avar age: Int = 25
Bval height = Int 170
Cval name String = "Alice"
Dvar weight = 70: Int
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kotlin variable declaration syntax

    Kotlin uses val or var followed by variable name, colon, type, then assignment.
  2. Step 2: Check each option

    var age: Int = 25 matches this syntax: var age: Int = 25. Others have syntax errors.
  3. Final Answer:

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

    Correct syntax uses colon before type [OK]
Quick Trick: Use colon (:) before type in declaration [OK]
Common Mistakes:
MISTAKES
  • Omitting colon before type
  • Placing type after value
  • Using wrong order of keywords

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes