Is this inheritance... correct?

Report a typo

Which of these examples utilize interface inheritance incorrectly, causing compilation errors?

#1

interface MyInterface {
    val myProperty: Int
    fun myMethod(): Int = 10
    fun mySecondMethod() { print("Hola!") }
}

interface MyInterface2 {
    val myProperty: Int
    fun myThirdMethod() = print("Hola amigos!")
}

class MyClass : MyInterface, MyInterface2 {
    override val myProperty: Int = 10
}

#2

interface MyInterface {
    val myProperty: Int
    fun myMethod(): Int = 10
    fun mySecondMethod() { print("Hola!") }
}

interface MyInterface2 {
    val myProperty: Int
    fun myThirdMethod() = print("Hola amigos!")
}

class MyClass : MyInterface, MyInterface2 {}

#3

interface MyInterface {
    val myProperty: Int
    fun myMethod(): Int = 10
    fun mySecondMethod() { print("Hola!") }
}

interface MyInterface2 {
    val myProperty: Int
    fun myThirdMethod() = print("Hola amigos!")
}

class MyClass(override val myProperty: Int) : MyInterface, MyInterface2 {}

#4

interface MyInterface {
    val myProperty: Int
    fun myMethod(): Int = 10
    fun mySecondMethod() { print("Hola!") }
}

interface MyInterface2 {
    val myProperty: Int
    fun myThirdMethod() = print("Hola amigos!")
}

class MyClass : MyInterface, MyInterface2 {
    override val myProperty: Int
        get() = 10

    override fun myMethod(): Int { return 127312 }

    override fun mySecondMethod() { print("Hello.") }

    override fun myThirdMethod() = println()
}
Select one option from the list
___

Create a free account to access the full topic