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()
}
image
喜欢可以加Q群号:874826112,一起学习,成长,交流工作经验,
记得要点赞,评论哦😯;
更多相关内容请点击主页查看,有你想不到的惊喜😂....
简书: https://www.jianshu.com/u/88db5f15770d
网友评论