We can use the super keyword to access the parent class constructor. The super keyword can call both parameterized and non-parameterized constructors depending on the situation. The syntax is given below.
Syntax:
:super();
Example –
- // Base class called Parent
- class Parent
- {
- Parent()
- {
- print(“This is the super class constructor”);
- }
- }
- // Child class Super
- class Child extends Parent
- {
- Child():super() // Calling super class constructor
- {
- print(“This is the sub class constructor”);
- }
- }
- void main() {
- // Creating object of sub class
- Child c = new Child();
- }
Output
This is the super class constructor This is the sub class constructor Explanation The syntax of Dart language is too close to C# language We called the parent class constructor using the super keyword, which is separated by : (colon). The delegate a superclass constructor, we should put the superclass as an initializer.