Recall & Review
beginner
What does
var mean in Kotlin?var declares a variable whose value can change (mutable).
Click to reveal answer
beginner
How do you declare a variable that cannot change in Kotlin?
Use val to declare an immutable (read-only) variable.
Click to reveal answer
beginner
What happens if you try to reassign a
val variable?Kotlin will give a compile error because val variables cannot be reassigned.
Click to reveal answer
beginner
Example: <br>
var count = 5<br>count = 10<br>What is the value of count after reassignment?The value of count is 10 because var allows changing the value.
Click to reveal answer
beginner
Why use
var instead of val?Use var when you need to change the value later, like a counter or user input.
Click to reveal answer
Which keyword declares a mutable variable in Kotlin?
✗ Incorrect
var declares a mutable variable that can be reassigned.
What happens if you try to assign a new value to a
val variable?✗ Incorrect
val variables cannot be reassigned; Kotlin gives a compile-time error.
Which of these is a correct way to declare a mutable integer variable with initial value 3?
✗ Incorrect
var number = 3 declares a mutable variable with value 3.
If you want a variable that never changes, which keyword do you use?
✗ Incorrect
val declares an immutable variable that cannot be reassigned.
What is the main difference between
var and val?✗ Incorrect
var allows changing the value; val does not.
Explain the difference between
var and val in Kotlin.Think about whether the variable's value can change after you set it.
You got /4 concepts.
Give an example where you would use
var instead of val.Think about situations where the value needs to update.
You got /4 concepts.