``` /// 定义一个Dart 类
class Person { String name; int age; Person(this.name, this.age) {
print('Person: constructor');
print(this.name);
print(this.age); } }
class Student extends Person { String _school; // 私有变量 类之外访问不到 String city; String country; String name; Student(this._school,String name, int age, {
this.city,
this.country = '中国' }) : name = '$country.$city',
super(name, age) {
print('super:constructor'); }
Student.cover(Student stu) : super(stu.name, stu.age) {
print("命名构造方法:"); }
void info() {
print('scholl:$_school');
print('name:${this.name}');
print('age:$age');
print('city:$city'); } } ``
print(this.name);
print(this.age); 里面在 调用命名构造器的时候 会出现null的情况。
解锁Flutter开发新姿势,,系统掌握Flutter开发核心技术。
了解课程