class Eat {
void eat() {
print('吃');
}
}
class Sleep {
void sleep() {
print('睡');
}
}
class Person with Eat, Sleep {
int age;
String name;
Person(this.name, this.age);
void sayhi() {
print('hello');
}
void printInfo() {
print('姓名:${this.name}-----年龄:${this.age}');
}
}
void main(List<String> args) {
Person p = new Person('jack', 20);
print(p.name);
print(p.age);
p.eat();
p.sleep();
p.sayhi();
p.printInfo();
}
输出结果:
jack
20
吃
睡
hello
姓名:jack-----年龄:20
本文深入探讨了Dart编程语言在Flutter框架下如何实现子类继承多个父类的机制,包括接口继承、混合类(mixins)的使用以及多重继承带来的优势和挑战。通过实例解析,帮助开发者更好地理解和应用这一特性。
3712

被折叠的 条评论
为什么被折叠?



