main(List<String> args) {
final man = SuperMan();
man.running();
man.flyering();
}
class Animal {
void running() {
print("Animal..running");
}
void eatting() {
}
}
mixin Runner {
void running() {
print("Runner..running");
}
}
mixin Flyer {
void flyering() {
print("Flyer..running");
}
}
// 混入的语法:1.定义可混入的类时,不能用class,mixin
// 2.他是使用with来进行的混入
// mixi混入继承可以实现类似多继承
// ⚠️执行顺序:最高级的是自己、没有自己的用混入、都没有用父类、在没有就报错
class SuperMan with Runner, Flyer {
@override
void flyering() {
// TODO: implement flyering
super.flyering();
print("SuperMan Flyer..running");
}
@override
void running() {
// TODO: implement running
print("SuperMan Runner..running");
}
}
网友评论