父类Human.kt
/**
* 抽象的人类
*/
abstract class Human(var name:String){
abstract fun eat()
}
子类Man.kt
/**
* 男人
*/
class Man(name:String) :Human(name){
override fun eat() {
println("${name}卡哇娃的大口吃")
}
}
子类Woman.kt
/**
* 女人
*/
class Woman(name:String) :Human(name){
override fun eat() {
println("${name}哇哇哇的小口吃")
}
}
Test.kt
fun main(args:Array<String>){
var person1 = Man("金三胖")
person1.eat()
var person2 = Woman("慈禧太后")
person2.eat()
}