abstract class Animal {
// properties
String name;
double speed;
// constructor
Animal(this.name, this.speed);
// abstract method
void run();
}
// mixin CanRun is only used by class that extends Animal
// 其实就是把 mixin CanRun 依附于 Animal 上面
mixin CanRun on Animal {
// implementation of abstract method
@override
void run() => print('$name is Running at speed $speed');
}
class Dog extends Animal with CanRun {
// constructor
Dog(String name, double speed) : super(name, speed);
}
void main() {
var dog = Dog('My Dog', 25);
dog.run();
}
// Not Possible
// class Bird with Animal { }
Dart on keyword
发布时间 2023-12-31 19:12:24作者: sqmw