abstract class A{ String name; printA(); } abstract class B{ printB(); } class C implements A,B{ //鼠标放在C处,选择快速修复 @override String name; @override printA() { print(‘printA‘); } @override printB() { // TODO: implement printB return null; } } void main(){ C c=new C(); c.printA(); }
//A类和B类不能继承其他类
class A { String info="this is A"; void printA(){ print("A"); } } class B { void printB(){ print("B"); } } class C with A,B{ } void main(){ var c=new C(); c.printA(); c.printB(); print(c.info); }
class Person{ String name; num age; Person(this.name,this.age); printInfo(){ print(‘${this.name}----${this.age}‘); } void run(){ print("Person Run"); } } class A { String info="this is A"; void printA(){ print("A"); } void run(){ print("A Run"); } } class B { void printB(){ print("B"); } void run(){ print("B Run"); } } class C extends Person with B,A{ //C继承Person,然后mixins B和A C(String name, num age) : super(name, age); } void main(){ var c=new C(‘张三‘,20); c.printInfo(); // c.printB(); // print(c.info); c.run(); //当A和B中有同样的方法时,with B,A 谁在后执行谁 }
class A { String info="this is A"; void printA(){ print("A"); } } class B { void printB(){ print("B"); } } class C with A,B{ } void main(){ var c=new C(); print(c is C); //true print(c is A); //true print(c is B); //true }
11.Dart中一个类实现多个接口 以及Dart中的Mixins
原文:https://www.cnblogs.com/The-Chao/p/11924019.html