Dart 类的继承
xxxixxxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14

class Person {
String name;
int age;

Person(this.name, this.age);
getInfo() {
print('$name --- $age');
}

work() {
print("object 努力学习");
}
}

继承、重写父类方法

使用 extends 关键字继承

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Zp extends Person {
String sex;
Zp(String name, int age, [String sex = '男']) : super(name, age) {
this.sex = sex;
}

faGongZi({int money}) {
print('发工资了 $money');
super.work();
work();
}

//MARK: 重写父类方法
@override
getInfo() {
print('$name 今年 $age 很有钱');
}
}
  • Post title:Dart 类的继承
  • Post author:xxxixxxx
  • Create time:2020-12-27 11:48:00
  • Post link:https://xxxixxx.github.io/2020/12/27/300-Dart基础4/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments