Recall & Review
beginner
What does the
? suffix mean in Kotlin types?It means the variable can hold either a value of that type or
null. For example, String? means a variable can be a string or null.Click to reveal answer
beginner
How do you declare a nullable integer variable in Kotlin?
You add a
? after the type. For example: var number: Int? = null means number can be an integer or null.Click to reveal answer
intermediate
Why does Kotlin use nullable types instead of allowing
null everywhere?To prevent errors caused by
null values, called NullPointerExceptions. Nullable types force you to check for null before using the value.Click to reveal answer
beginner
What happens if you try to assign
null to a non-nullable type in Kotlin?The code will not compile. Kotlin requires you to explicitly mark a type as nullable with
? to allow null values.Click to reveal answer
intermediate
How do you safely access a property or method of a nullable variable in Kotlin?
Use the safe call operator
?.. For example, name?.length returns the length if name is not null, otherwise it returns null.Click to reveal answer
What does
String? mean in Kotlin?✗ Incorrect
String? means the variable can hold a string or null.Which operator safely accesses a property of a nullable variable?
✗ Incorrect
The safe call operator
?. accesses properties only if the variable is not null.What happens if you assign null to a non-nullable type?
✗ Incorrect
Kotlin prevents assigning null to non-nullable types at compile time.
How do you declare a nullable Boolean variable named
flag?✗ Incorrect
You declare it as
var flag: Boolean? = null to allow null values.Why does Kotlin use nullable types?
✗ Incorrect
Nullable types help avoid errors by requiring you to handle null values explicitly.
Explain what nullable types are in Kotlin and how the
? suffix works.Think about how Kotlin prevents null errors.
You got /3 concepts.
Describe how to safely use a nullable variable's property or method in Kotlin.
How do you avoid crashes when a variable might be null?
You got /3 concepts.