![]() |
VOOZH | about |
In Dart, the super keyword is used to refer immediate parent class object. It is used to call properties and methods of the superclass. It does not call the method, whereas when we create an instance of subclass than that of the parent class is created implicitly so super keyword calls that instance.
Syntax:
// To access parent class variables
super.variable_name;
// To access parent class method
super.method_name();
Example :
Output:
You are inside the Parent constructor!!
You are inside the Child constructor!!
Example :
Output:
Geeks for GeeksExample :
Output:
You are calling method of parent class.
Welcome to Gfg!!
You are inside parent class.
While super keyword is used to call parent class, this keyword is used to call the class itself.
Example :
Output:
Welcome to Geeks for GeeksTo know more about this keyword refer this article: Dart - this keyword.