我正在尝试创建一个名为西类牙数据的抽象类
然后我想创建另一个名为字母表的类来扩展西类牙数据
我收到一个错误:父类(super class)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(
)
}
最佳答案
你需要引用parent class
的属性您的 class
正在延伸。您可以使用 super
执行此操作关键词。
The super() method on a class constructor allows a subclass to pass arguments and execute the constructor of its superclass.
下面的代码有效: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(){}
}
关于flutter - 你如何在 dart 中使用抽象类进行继承?错误 : superclass SpanishData doesn't have a zero argument constructor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62964536/