An *_*ran 4 inheritance abstract dart flutter
我正在尝试创建一个名为SpanishData 的抽象类然后我想创建另一个名为alphabet 的类来扩展西班牙语数据
我收到错误:超类 SpanishData 没有零参数构造函数。我该如何解决?
这是我的代码:
abstract class SpanishData{
String englishWord;
String spanishWord;
String mp3;
SpanishData(this.englishWord,this.spanishWord,this.mp3);
void getList (){
}
}
//the alphabet class
import '../SpanishDataAbstract.dart';
class Alphabet extends SpanishData{
@override
void getList(
)
}
Run Code Online (Sandbox Code Playgroud)
parent class您需要参考您正在扩展的属性class。您可以使用super关键字来完成此操作。
The super() method on a class constructor allows a subclass to pass arguments and execute the constructor of its superclass.
Run Code Online (Sandbox Code Playgroud)
下面的代码有效:
abstract class SpanishData{
String englishWord;
String spanishWord;
String mp3;
SpanishData(this.englishWord,this.spanishWord,this.mp3);
void getList (){
}
}
class Alphabet extends SpanishData{
// create a constructor of the alphabet class and call the parent constructor
Alphabet(String englishWord, String spanishWord, String mp3) : super(englishWord, spanishWord, mp3);
@override
void getList(){}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2348 次 |
| 最近记录: |