Vidyalelo
Computer Science · Q285

Kotlin Programming MCQ for Competitive Exams, Interviews, and Certifications

Engineering and GATE · Computer Science · question 285

Q285

Why doesn't this code compile? val addend = 1 infix fun Int.add(added: Int=1) = this + addend fun main() val msg = "Hello" println( msg shouldMatch "Hello") println( 10 multiply 5 + 2) println( 10 add 5)

A.
infix function must be marked public
B.
In Kotlin, add is a keyword
C.
Extension functions use it, not this, as the default parameter name
D.
infix functions cannot have default values
Answer

Answer: Option D

Solution

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