Kotlin API Flashcards

(27 cards)

1
Q

What is Kotlin?

A

Kotlin is a statically typed programming language for the JVM, Android, JavaScript, and native.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: Kotlin is fully interoperable with Java.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Fill in the blank: Kotlin is designed to be fully ________ with Java.

A

interoperable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What keyword is used to declare a variable in Kotlin?

A

val for immutable and var for mutable variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which function is used to create a new instance of a class in Kotlin?

A

The constructor function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the ‘data’ keyword signify in a Kotlin class?

A

It indicates that the class is a data class, which automatically provides methods like equals(), hashCode(), and toString().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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)

A

B) function myFunction()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the purpose of the ‘companion object’ in Kotlin?

A

It allows you to define static members for a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True or False: In Kotlin, null safety is built into the type system.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Fill in the blank: To declare a variable that can hold null values, you append a ________ to the type.

A

?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a ‘sealed class’ in Kotlin?

A

A sealed class restricts class hierarchies to a limited set of types, allowing exhaustive ‘when’ expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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.

A

D) It indicates that a function is overriding a superclass method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the primary use of ‘extension functions’ in Kotlin?

A

To add new functionality to existing classes without modifying their source code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

True or False: Kotlin supports functional programming features.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the difference between ‘let’ and ‘apply’ in Kotlin?

A

‘let’ is used to execute a block of code on the result of a nullable expression, while ‘apply’ is used to initialize an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Fill in the blank: The ________ function is used to handle exceptions in Kotlin.

17
Q

What is the purpose of the ‘inline’ keyword in Kotlin?

A

To reduce the overhead of function calls in lambdas by inlining the code at the call site.

18
Q

What is a ‘lambda expression’ in Kotlin?

A

A lambda expression is a function without a name that can be treated as a value.

19
Q

Multiple Choice: Which of the following is a valid way to create a list in Kotlin?
A) val list = List(5) { it * 2 }
B) val list = listOf(1, 2, 3)
C) val list = arrayListOf(1, 2, 3)
D) All of the above

A

D) All of the above

20
Q

What does the ‘lateinit’ modifier do in Kotlin?

A

It allows you to declare a non-null variable that will be initialized later.

21
Q

True or False: In Kotlin, you can define a function inside another function.

22
Q

What is the significance of the ‘suspend’ keyword in Kotlin?

A

It indicates that a function can be paused and resumed, making it suitable for asynchronous programming.

23
Q

Fill in the blank: The ________ function is used to launch a coroutine in Kotlin.

24
Q

What is the purpose of the ‘withContext’ function in Kotlin coroutines?

A

It changes the context of a coroutine and is used to switch between threads.

25
Multiple Choice: Which of the following is NOT a collection type in Kotlin? A) List B) Set C) Map D) Tuple
D) Tuple
26
What is the default visibility modifier for classes in Kotlin?
public
27
Fill in the blank: The ________ function is used to create a new coroutine scope.
CoroutineScope