menu

Kotlin Basics

Kotlin Basics - Important Points


16. What is a coroutine in Kotlin?

A. A type of function that can be suspended and resumed later.

B. A type of loop that runs in the background.

C. A type of class that is used for creating objects.

D. A type of variable that can be shared between threads.

Discuss Work Space

Answer: option a

Explanation:

Coroutines are a way to write asynchronous code in a more concise and readable way, allowing functions to be suspended and resumed later.

17. Which of the following is true about extension functions in Kotlin?

A. Extension functions are a way to add new functionality to existing classes without having to modify their source code.

B. Extension functions can only be defined for classes that are part of the Kotlin standard library.

C. Extension functions are not supported in Kotlin.

D. Extension functions can only be defined for classes that are marked as "open".

Discuss Work Space

Answer: option a

Explanation:

Extension functions allow you to add new functions to existing classes without having to modify their source code, making it easier to extend the functionality of existing classes.

18. What is the Elvis operator in Kotlin?

A. A type of operator used for bitwise operations.

B. A type of operator used for arithmetic operations.

C. A type of operator used for null safety.

D. A type of operator used for logical operations.

Discuss Work Space

Answer: option c

Explanation:

The Elvis operator in Kotlin (?:) is used to handle null values, allowing you to provide a default value or throw an exception if a value is null.

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

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

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

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

D. val and "var" are not supported in Kotlin.

Discuss Work Space

Answer: option b

Explanation:

In Kotlin, "val" is used for variables that are immutable or constant, while "var" is used for variables that can be reassigned or changed.

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

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

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

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

D. is and "as" are not supported in Kotlin.

Discuss Work Space

Answer: option a

Explanation:

In Kotlin, "is" is used to check if an object is of a specific type, while "as" is used to cast an object to a specific type.


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