Vidyalelo
Computer Science · Q291

Kotlin Programming MCQ for Competitive Exams, Interviews, and Certifications

Engineering and GATE · Computer Science · question 291

Q291

You are creating a Kotlin unit test library. What else should you add to make the following code compile without error? fun String.shouldEqual(value: String) = this == value fun main() val msg = "test message" println(msg shouldEqual "test message")

A.
The extension function should be marked public
B.
Add the prefix operator to the shouldMatch extension function
C.
The code is not legal in Kotlin (should be println(msg.shouldEqual("test message")))
Answer
D.
Add the prefix infix to the shouldMatch extension function

Answer: Option C

Solution

Answer: Option C
No explanation is given for this question Let's Discuss on Board