Skip to content

Kotlin Programming

Master Kotlin Programming with 50 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.

🎓 50 cards ⏱️ ~25 min Advanced
Study Full Deck →
Share: 𝕏 Twitter LinkedIn WhatsApp

🎯 What You'll Learn

Preview Questions

12 shown

What is null safety in Kotlin?

Show ▼

Null safety is a Kotlin feature that eliminates NullPointerException at compile time.
By default, variables cannot hold null. You must explicitly declare a type as nullable using ?, e.g. var name: String? = null.

How do you declare a nullable type in Kotlin?

Show ▼

Append a ? to the type declaration:
var name: String? = null
Without the ?, the compiler will reject any attempt to assign null.

What is the safe call operator in Kotlin?

Show ▼

The safe call operator ?. allows you to access a property or call a method on a nullable object without risking a NullPointerException:
val length = name?.length
If name is null, the expression returns null instead of throwing.

What is the Elvis operator in Kotlin?

Show ▼

The Elvis operator ?: provides a default value when an expression is null:
val len = name?.length ?: 0
If the left side is null, the right side is used.

What does the non-null assertion operator (!!) do?

Show ▼

The !! operator converts a nullable type to a non-null type and throws a KotlinNullPointerException if the value is null:
val len = name!!.length
Use it only when you are absolutely certain the value is not null.

What is a data class in Kotlin?

Show ▼

A data class automatically generates equals(), hashCode(), toString(), copy(), and componentN() functions:
data class User(val name: String, val age: Int)
It is designed to hold immutable data.

What methods does a Kotlin data class auto-generate?

Show ▼

A data class auto-generates:equals() and hashCode()toString() in the form User(name=John, age=30)copy() for creating modified copiescomponentN() functions for destructuring

How does the copy() function work on a data class?

Show ▼

copy() creates a new instance with the same values, allowing you to override specific properties:
val user2 = user1.copy(age = 25)
This is useful for working with immutable data objects.

What are extension functions in Kotlin?

Show ▼

Extension functions let you add new functions to existing classes without modifying their source code:
fun String.addExclamation(): String = this + "!"
Called as: "Hello".addExclamation() returns "Hello!".

Can extension functions access private members of a class?

Show ▼

No. Extension functions are resolved statically and do not actually modify the class. They cannot access private or protected members of the receiver class.

What is a sealed class in Kotlin?

Show ▼

A sealed class restricts which classes can inherit from it. All subclasses must be defined in the same file (or same package in Kotlin 1.5+):
sealed class Result
data class Success(val data: String) : Result()
data class Error(val msg: String) : Result()

Why are sealed classes useful with when expressions?

Show ▼

Sealed classes allow the compiler to verify that a when expression covers all possible cases, eliminating the need for an else branch:
when (result) {
  is Success -> ...
  is Error -> ...
}

🎓 Start studying Kotlin Programming

🎮 Study Modes Available

🔄

Flashcards

Flip to reveal

🧠

Focus Mode

Spaced repetition

Multiple Choice

Test your knowledge

⌨️

Type Answer

Active recall

📚

Learn Mode

Multi-round mastery

🎯

Match Game

Memory challenge

Related Topics in Programming

📖 Learning Resources