menu

Kotlin Basics


1. Which of the following is true about higher-order functions in Kotlin?

Higher-order functions take other functions as parameters or return functions as results.

Higher-order functions are only used for mathematical calculations.

Higher-order functions are not supported in Kotlin.

Higher-order functions are used to create singleton objects.


2.

What is the output of the following code?

fun main() {
val list = listOf(1, 2, 3)
val doubledList = list.map { it * 2 }
println(doubledList)
}

[1, 2, 3]

[2, 4, 6]

[1, 2, 3, 2, 4, 6]

This code will not compile.


3. What is the Elvis operator in Kotlin?

A type of operator used for bitwise operations.

A type of operator used for arithmetic operations.

A type of operator used for null safety.

A type of operator used for logical operations.


4. What is the syntax for a lambda expression in Kotlin?

{x, y -> x + y}

(x, y) => x + y

[x, y] -> x + y

(x, y) -> {x + y}


5. What is the difference between "is" and "as" in Kotlin?

is is used for type checking, while "as" is used for casting between types.

is is used for casting between types, while "as" is used for type checking.

is and "as" are interchangeable and can be used interchangeably.

is and "as" are not supported in Kotlin.


6. Which of the following is an example of inheritance in Kotlin?

class MyClass {}

interface MyInterface {}

class MySubclass : MyClass {}

All of the above


7. What is the Elvis operator in Kotlin?

??

::

!!

//


8. What is the difference between a range and an array in Kotlin?

A range is a collection of values between two endpoints, while an array is a fixed-size collection of elements.

A range is a fixed-size collection of elements, while an array is a variable-size collection of elements.

There is no difference between a range and an array in Kotlin.

A range and an array are both used to store collections of values.


9.

What is Kotlin?

A programming language

A database management system

A web framework

A markup language


10. What is the difference between a class and an object in Kotlin?

A class is a blueprint for creating objects, while an object is a singleton instance of a class.

A class is a singleton instance of an object, while an object is a blueprint for creating classes.

There is no difference between a class and an object in Kotlin.

A class and an object are both used to create instances of a class.