'Calling consturctor of superclass from constructor's body of subclass in Dart
I am a beginner in Dart. :-)
I wonder why I can't call the parent class constructor inside the child class constructor body.
class Parent {
String? name;
Parent(this.name);
Parent.namedConstructor(this.name);
}
class Child extends Parent {
// Child(String name) : super(name); // It's OK
// Child(String name) : super.namedConstructor(name); // It's OK, too.
Child(String name) {
super(name); // Error
super.namedConstructor(name); // Error
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
