Bird
0
0

Identify the error in this Kotlin code:

medium📝 Debug Q6 of 15
Kotlin - Variables and Type System
Identify the error in this Kotlin code:
fun main() {
    const val MAX = 100
    println(MAX)
}
AMissing semicolon after declaration
B<code>const val</code> cannot be declared inside a function
CMAX should be a var, not val
Dprintln syntax is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check where const val is declared

    Here, const val MAX is declared inside a function, which is not allowed.
  2. Step 2: Validate other options

    There is no semicolon needed, val is correct, and println syntax is fine.
  3. Final Answer:

    const val cannot be declared inside a function -> Option B
  4. Quick Check:

    const val location error = A [OK]
Quick Trick: const val must be outside functions [OK]
Common Mistakes:
MISTAKES
  • Declaring const val inside functions
  • Adding unnecessary semicolons
  • Confusing val and var for constants

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes