menu

Kotlin Basics


1. 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}


2. 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.


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 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.


5.

What is Kotlin?

A programming language

A database management system

A web framework

A markup language


6. What is the primary use case of Kotlin?

Mobile app development

Web development

Database management

Machine learning


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

class MyClass {}

interface MyInterface {}

class MySubclass : MyClass {}

All of the above


8. What is the difference between a primary constructor and a secondary constructor in Kotlin?

A primary constructor is called before any secondary constructors, while a secondary constructor is called before the primary constructor.

A primary constructor is defined inside the class definition, while a secondary constructor is defined outside the class definition.

A primary constructor takes parameters that are used to initialize properties, while a secondary constructor can have additional logic or functionality.

There is no difference between a primary and a secondary constructor in Kotlin.


9. What is the difference between "val" and "var" in Kotlin?

val is used for variables that can be changed, while "var" is used for variables that are constant.

val is used for variables that are constant, while "var" is used for variables that can be changed.

val and "var" are interchangeable and can be used interchangeably.

val and "var" are not supported in Kotlin.


10. What is the Elvis operator in Kotlin?

??

::

!!

//