menu

Kotlin Functions

Kotlin Functions - Important Points


21. What is a default argument in Kotlin?

A. An argument that is required to be passed to a function

B. An argument that is passed using a named parameter

C. An argument that has a default value specified in the function declaration

D. An argument that is passed using a lambda expression

Discuss Work Space

Answer: option c

Explanation:

A default argument in Kotlin is an argument that has a default value specified in the function declaration, so it can be omitted when calling the function.

22. Which of the following is a valid way to call a function with named arguments in Kotlin?

A. sum(1, 2, x = { x, y -> x + y })

B. sum(1, 2, op = { x, y -> x + y })

C. sum(1, 2, { x, y -> x + y }, op = true)

D. sum(x = 1, y = 2) { x, y -> x + y }

Discuss Work Space

Answer: option d

Explanation:

Option D is a valid way to call a function with named arguments in Kotlin, by specifying the name of each argument and its corresponding value in the function call.


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