Bird
0
0

What is a key characteristic of a const val in Kotlin?

easy📝 Conceptual Q1 of 15
Kotlin - Variables and Type System
What is a key characteristic of a const val in Kotlin?
AIt is a compile-time constant and cannot be changed at runtime.
BIt can be assigned a value inside a function.
CIt can be reassigned multiple times.
DIt is only used for variables inside classes.
Step-by-Step Solution
Solution:
  1. Step 1: Understand what const val means

    const val declares a constant whose value is known at compile time and cannot be changed later.
  2. Step 2: Check each option against this rule

    Only It is a compile-time constant and cannot be changed at runtime. correctly states that const val is a compile-time constant and immutable.
  3. Final Answer:

    It is a compile-time constant and cannot be changed at runtime. -> Option A
  4. Quick Check:

    Constant property = C [OK]
Quick Trick: const val means fixed value known at compile time [OK]
Common Mistakes:
MISTAKES
  • Thinking const val can be changed later
  • Assuming const val can be assigned inside functions
  • Confusing const val with regular val

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes