Computer scienceProgramming languagesKotlinObject-oriented programmingObject-oriented programming usage

Packages and imports

Espresso

Report a typo

We have a package called coffee in a file, and we want to use the classes Coffee and Drink in another file of our project in a different package.
What should we write in the new file where we want to use them?

package coffee

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)
Enter a short text
___

Create a free account to access the full topic