KotlinKotlinKotlin开发指南

kotlin 类和对象 之接口

2017-07-20  本文已影响34人  Lost_Robot

关键字:   interface

  • 既包含抽象方法的声明,也包含实现。
interface MaxNum {

    val boob: Int  //抽象属性
    val poop: String      //带访问器实现的属性
        get() = "MaxNum"

    fun getMaxNum(): Int

    fun printS() {
        System.out.print("Hello  S,How  are You?")

    }

    fun print() {
        System.out.print("S MaxNum >>" + boob)
    }

}

interface MinNum {


    fun printS() {
        System.out.print("Hello  MinNum,How  are  You?")

    }

    fun print()

}

class MMMum : MaxNum, MinNum {
    override val boob: Int
        get() = 99

    override fun getMaxNum(): Int {

        return boob
    }

    override fun printS() {

        //如何处理冲突
        super<MaxNum>.printS()
        super<MinNum>.printS()
        System.out.print("MMMum>>>" + boob)

    }


    override fun print() {

        System.out.print("boob is num>>" + boob)

    }


}

上一篇下一篇

猜你喜欢

热点阅读