menu

Kotlin Basics

Kotlin Basics - Important Points


6. Which of the following is an example of a string interpolation in Kotlin?

A. The answer is + answer

B. The answer is $answer

C. The answer is {answer}

D. The answer is [answer]

Discuss Work Space

Answer: option b

Explanation:

String interpolation allows you to embed a variable's value directly into a string.

7. Which of the following is a valid function declaration in Kotlin?

A. fun myFunction()

B. fun myFunction(): String

C. fun myFunction(): Int = 42

D. All of the above

Discuss Work Space

Answer: option d

Explanation:

All of these are valid ways to declare a function in Kotlin.

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

A. {x, y -> x + y}

B. (x, y) => x + y

C. [x, y] -> x + y

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

Discuss Work Space

Answer: option d

Explanation:

The syntax for a lambda expression in Kotlin is (parameters) -> expression.

9. What is the Elvis operator in Kotlin?

A. ??

B. ::

C. !!

D. //

Discuss Work Space

Answer: option a

Explanation:

The Elvis operator (?:) is used to provide a default value when a variable is null.

10. Which of the following is true about nullable types in Kotlin?

A. All types in Kotlin are nullable by default.

B. Only reference types in Kotlin can be nullable.

C. All types in Kotlin are non-nullable by default.

D. Nullable types cannot be used in Kotlin.

Discuss Work Space

Answer: option c

Explanation:

Unlike in Java, Kotlin's type system distinguishes between nullable and non-nullable types. Non-nullable types are the default, and you must explicitly indicate when a type is nullable.


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now