[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() }
标签:Overriding,val,course,Rules,Kotlin,println,override,learn,fun 来源: https://www.cnblogs.com/Answer1215/p/13800656.html