8 kotlin之interface和 abstract的使用
interface IDatabase {
fun connect()
fun close()
}
abstract class Database(databaseName: String) : IDatabase {
val databaseName: String = databaseName
var connectString: String = ""
fun showInfo() {
println("databaseName.: $databaseName")
}
}
class Oracle(connectString: String) : Database("Oracle") {
init {
println("init....")
super.connectString = connectString
}
override fun connect() {
println("$databaseName connect $connectString")
}
override fun close() {
println("$databaseName close")
}
}
fun main() {
var oracle = Oracle("数据库链接")
oracle.showInfo();
oracle.connect()
oracle.close()
}
喜欢可以加Q群号:874826112,一起学习,成长,交流工作经验,
记得要点赞,评论哦😯;
更多相关内容请点击主页查看,有你想不到的惊喜😂…
简书: https://www.jianshu.com/u/88db5f15770d
csdn:https://me.csdn.net/beyondforme
掘金:https://juejin.im/user/5e09a9e86fb9a016271294a7