Quiz: Operator Overloading

Test your understanding of the concepts discussed in this chapter.

1

In Kotlin, which method should be defined in a class to be able to use the - operator on its instances?

data class Complex(val real: Double, val imaginary: Double) {
    operator fun ____(another: Complex) = Complex(
        real - another.real,
        imaginary - another.imaginary
    )
}
A)

minus

B)

subtract

C)

minusAssign

D)

-

Question 1 of 50 attempted

Get hands-on with 1200+ tech skills courses.