Computer scienceProgramming languagesKotlinObject-oriented programmingObject-oriented programming usage

hashCode and equals

Espresso

Report a typo

What is the output of the following code?

open class Drink(val cost: Int) {
    override fun equals(other: Any?): Boolean {
        return other is Drink && cost == other.cost
    }
}

class Coffee(cost: Int, val name: String) : Drink(cost)

fun main() {
    val coffee1 = Coffee(10, "Latte")
    val coffee2 = Coffee(10, "Cappuccino")

    println(coffee1 == coffee2) 
}
Enter a short text
___

Create a free account to access the full topic