Dart接口示例
interface Dartinterface{ MyInterface(); } class BasicInterface implements Dartinterface{ MyInterface(){ print("I am a inteface"); } } void main(){ BasicInterface obj = new BasicInterface(); obj.MyInterface(); }
- 接口的默认类
它是相对于其他面向对象编程语言所特有的新特性,接口的默认类示例如下
接口的默认类示例
interface Dartinterface default BasicInterface{ MyInterface(); Dartinterface(); } class BasicInterface implements Dartinterface{ MyInterface(){ print("I am a inteface"); } } void main(){ //BasicInterface obj = new BasicInterface(); Dartinterface obj = new Dartinterface(); obj.MyInterface(); }
Dart接口
接口定义了如何与对象交互的方式。
在接口中,我们可以声明抽象方法(意味着我们可以在其子类中声明身体),基本上它用于解决多重继承的问题。
接口语法
interface identifier interface name{ //.........Abstract Method................. } //例如: interface MyInterface{ AbstactMethod(); }
日期:2020-04-11 23:04:02 来源:oir作者:oir