[英]How do you perform inheritance with abstract classes in dart? error : superclass SpanishData doesn't have a zero argument constructor
I'm trying to create an abstract class called SpanishData And then I want to create another class called alphabet that extends Spanish data我正在尝试创建一个名为 SpanishData 的抽象 class 然后我想创建另一个名为字母表的 class 扩展西班牙数据
I'm getting an error: the superclass SpanishData doesn't have a zero-argument constructor.我收到一个错误:超类 SpanishData 没有零参数构造函数。 How do I fix this?我该如何解决?
Here is my code:这是我的代码:
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(
)
}
You need to refer to the properties of the parent class
your class
is extending.您需要参考您的class
正在扩展的parent class
的属性。 You can do this using the super
keyword.您可以使用super
关键字来执行此操作。
The super() method on a class constructor allows a subclass to pass arguments and execute the constructor of its superclass.
The code below works:下面的代码有效:
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(){}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.