Student 定义的name不是和父类Person定义name重复了,而且在子类还要单独初始化
来源:5-8 带你揭开Flutter中的面向对象(命名构造方法)
慕神8170126
2023-08-08
class Person {
String name;
int age;
Person(this.name, this.age);
@override
String toString() {
return “name:name,age:name, age:name,age:age”;
}
}
class Student extends Person {
late String _school; // 通过下划线来标识私有字段(变量)
String? city;
String? country;
late String name;
Student(this._school, String name, int age, {required this.city, this.country = “China”}): name=‘country.country.country.city’, super(name, age);
Student.cover(Student stu):super(stu.name, stu.age);
}
写回答
1回答
-
CrazyCodeBoy
2023-08-09
Student定义了name主要是实现对父类的重写。00
相似问题