Flutter 重写方法以向其添加函数
假设我们有:Flutter 重写方法以向其添加函数,flutter,dart,Flutter,Dart,假设我们有: class Human{ String name; Human(this.name); void printMyInfo(){ print("My name is ${this.name}"); } } class Bob extends Human{ int age; Bob(this.name, this.age) : super(name); } 有没有办法只添加下一行 print("My ag
class Human{
String name;
Human(this.name);
void printMyInfo(){
print("My name is ${this.name}");
}
}
class Bob extends Human{
int age;
Bob(this.name, this.age) : super(name);
}
有没有办法只添加下一行
print("My age is ${this.age}");
要在不重写以前的代码的情况下继承printMyInfo方法吗
我的目标是运行以获得以下输出:
My name is *;
My age is *;
通过只添加最后一个print方法类,Bob扩展了人类{
智力年龄;
Bobthis.name,this.age:supername;
无效printMyInfo{
super.printMyInfo;
我的年龄是$age;
}
}
只需重写您的方法。在要执行的地方添加对super的调用
@override
void printMyInfo(){
super.printMyInfo();
print("My age is ${this.age}");
}