Kotlin API Flashcards
What is Kotlin?
Kotlin is a statically typed programming language for the JVM, Android, JavaScript, and native.
True or False: Kotlin is fully interoperable with Java.
True
Fill in the blank: Kotlin is designed to be fully ________ with Java.
interoperable
What keyword is used to declare a variable in Kotlin?
val for immutable and var for mutable variables.
Which function is used to create a new instance of a class in Kotlin?
The constructor function.
What does the ‘data’ keyword signify in a Kotlin class?
It indicates that the class is a data class, which automatically provides methods like equals(), hashCode(), and toString().
Multiple Choice: Which of the following is NOT a valid way to declare a function in Kotlin?
A) fun myFunction()
B) function myFunction()
C) fun myFunction(param: Int)
D) fun myFunction(param1: Int, param2: String)
B) function myFunction()
What is the purpose of the ‘companion object’ in Kotlin?
It allows you to define static members for a class.
True or False: In Kotlin, null safety is built into the type system.
True
Fill in the blank: To declare a variable that can hold null values, you append a ________ to the type.
?
What is a ‘sealed class’ in Kotlin?
A sealed class restricts class hierarchies to a limited set of types, allowing exhaustive ‘when’ expressions.
Multiple Choice: What does the ‘override’ keyword do in Kotlin?
A) It creates a new function.
B) It modifies an existing function.
C) It indicates that a function is implementing an interface.
D) It indicates that a function is overriding a superclass method.
D) It indicates that a function is overriding a superclass method.
What is the primary use of ‘extension functions’ in Kotlin?
To add new functionality to existing classes without modifying their source code.
True or False: Kotlin supports functional programming features.
True
What is the difference between ‘let’ and ‘apply’ in Kotlin?
‘let’ is used to execute a block of code on the result of a nullable expression, while ‘apply’ is used to initialize an object.