日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

kotlin中既继承又实现_Kotlin程序| 解决继承中的主要冲突的示例

發布時間:2025/3/11 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 kotlin中既继承又实现_Kotlin程序| 解决继承中的主要冲突的示例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

kotlin中既繼承又實現

繼承中的主要沖突 (Overriding Conflicts in Inheritance)

  • It may appear, we inherit more than one implementation of the same method.

    看來,我們繼承了同一方法的多個實現。

  • Need to implement all the methods which we have inherited from multiple interfaces.

    需要實現我們從多個接口繼承的所有方法。

解決Kotlin中繼承中的主要沖突 (Resolving Overriding Conflicts in Inheritance in Kotlin)

package com.includehelp// declare interface interface One{// abstract functionfun myName()// function with implementationfun sayHello(){println("Hello, 'From Interface One' ")} }interface Two{// function with implementationfun sayHello(){println("Hello, 'From Interface Two' ")}// function with implementationfun myName(){println("My Name is Interface 'Two'")} }// class implementing interface class Three:One{// override interface abstract methodoverride fun myName() {println("My Name is Class Three")} }// class implementing more then one interfaces class Four:One,Two{// need to implement all the methods // which we have inherited from multiple interfacesoverride fun sayHello() {// Both interface have sayHello implementation in interfaces,// so explicitly define Interface name in super to call, // specific implementation from classsuper<One>.sayHello()super<Two>.sayHello()println("Hello, From Class 'Four' ")}// need to implement all the methods // which we have inherited from multiple interfacesoverride fun myName() {// called super type implementation of method,// only interface two have implementation of this method, // so need to explicitly define interface namesuper.myName()println("My Name is Class Four")}}// Main function, Entry point of program fun main(){// create class instanceval four = Four()// call methodsfour.myName()// call methodsfour.sayHello() }

Output:

輸出:

My Name is Interface 'Two' My Name is Class Four Hello, 'From Interface One' Hello, 'From Interface Two' Hello, From Class 'Four'

翻譯自: https://www.includehelp.com/kotlin/example-of-resolving-overriding-conflicts-in-inheritance.aspx

kotlin中既繼承又實現

總結

以上是生活随笔為你收集整理的kotlin中既继承又实现_Kotlin程序| 解决继承中的主要冲突的示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。