[Kotlin] Overriding Rules (super, final)

import java.util.*

/**
 * You can edit, run, and share this code. 
 * play.kotlinlang.org 
 */

abstract class Course(val topic: String, val price: Double) {
    open fun learn() {
        println("Learnign a $topic course")
    }
}

interface Readable {
    fun read() {
        println("Reading..")
    }
}

class KotlinCourse(): Course("Kotlin", 99.99), Readable {
    // final: don't allow child class to override learn()
    override final fun learn() {
        super<Course>.learn()
        super<Readable>.read()
        println("I want to learn Kotlin")
    }
    
    
    override fun read() {
        println("Leanring the kotlin")
    }
}


fun main() {
    val course = KotlinCourse()
    course.learn()
}

 

posted @ 2020-10-12 03:39  Zhentiw  阅读(59)  评论(0编辑  收藏  举报