How do I call a super constructor in Dart? Is it possible to call named super constructors?
this is file i am sharing with you, run it as it is. you'll learn how to call super constructor, and how to call super parameterized constructor.
/ Objectives
// 1. Inheritance with Default Constructor and Parameterised Constructor
// 2. Inheritance with Named Constructor
void main() {
var dog1 = Dog("Labrador", "Black");
print("");
var dog2 = Dog("Pug", "Brown");
print("");
var dog3 = Dog.myNamedConstructor("German Shepherd", "Black-Brown");
}
class Animal {
String color;
Animal(String color) {
this.color = color;
print("Animal class constructor");
}
Animal.myAnimalNamedConstrctor(String color) {
print("Animal class named constructor");
}
}
class Dog extends Animal {
String breed;
Dog(String breed, String color) : super(color) {
this.breed = breed;
print("Dog class constructor");
}
Dog.myNamedConstructor(String breed, String color) : super.myAnimalNamedConstrctor(color) {
this.breed = breed;
print("Dog class Named Constructor");
}
}