Examveda

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: Option D


This Question Belongs to Computer Science >> Kotlin Program

Join The Discussion

Related Questions on Kotlin Program

What is Kotlin?

A. A new version of Java.

B. A JavaScript framework.

C. A statically-typed programming language for the JVM, Android, and browser.

D. A database management system.