What is the super Keyword in Dart ?
The
super
keyword in Dart is used to refer to the object of the immediate parent class of the current child class.The
super
keyword is also used to call the parent class’s methods, constructor, and properties in the child class.
Benefits of the super keyword
When both the parent and the child have members with the same name,
super
can be used to access the data members of the parent class.super can keep the parent method from being overridden.
super can call the parent class’s parameterized constructor.
Syntax
// To access parent class variables super.variable_name; // To access parent class method super.method_name();
Example
class me { men() { print('Hiii'); } } class You extends me { void one() { super.men(); } } void main() { var one = You(); one.men(); }
Output
Hiii
Exited.