继承:
person.dart:
class Person{ String name; int age; String _birthday; bool get isAdult => age > 18; void run(){ print('Person run......'); } }
class_extends.dart:
import 'person.dart'; class Student extends Person{ @override // TODO: implement isAdult子类可以重写父类的方法 bool get isAdult => age > 15; @override void run() { // TODO: implement run print('Student run...'); } void study(){ print('Student study...'); } } void main(){ var student = new Student(); //可以继承父类的可见属性 student.name = 'Tom'; student.age = 16; print(student.isAdult); student.run(); }
继承中的构造方法:
抽象类:
接口:
MixIns:
操作符复写:
内容来源于网络如有侵权请私信删除
- 还没有人评论,欢迎说说您的想法!