Untitled

mail@pastecode.io avatar
unknown
kotlin
2 years ago
774 B
0
Indexable
Never
open class A {
    open fun method1() {
        println("A1")
    }
    open fun method2() {
        println("A2")
    }
}
class B : A() {
    override fun method1() {
        println("B2")
    }
    override fun method2() {
        println("A1"+"")
    }
}
class C : A() {
    override fun method1() {
        println("C1")
    }
    override fun method2() {
        println("C1"+"B2")
    }
}
class D : A() {
    override fun method1() {
        println("D1")
    }
    override fun method2() {
        println("D1"+"B2")
    }
}
fun main() {
    val element: Array<A> = arrayOf(D(), A(), C(), B())
    for (i in element.indices) {
        println(element[i].method1())
        println(element[i].method2())
        println()
    }
}