VOOZH about

URL: https://www.geeksforgeeks.org/dart/dart-super-and-this-keyword/

⇱ Dart - Super and This keyword - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Dart - Super and This keyword

Last Updated : 12 Jul, 2025

Super Keyword in Dart

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.

Advantages of super keyword

  • It can be used to access the data members of parent class when both parent and child have member with same name.
  • It is used to prevent overriding the parent method.
  • It can be used to call the parameterized constructor of the parent class.

Syntax:

// To access parent class variables
super.variable_name;

// To access parent class method
super.method_name();

Showing the flow of object creation in inheritance

Example :


Output:

You are inside the Parent constructor!!
You are inside the Child constructor!!


Accessing parent class variables

Example :


Output:

Geeks for Geeks


Accessing parent class methods

Example :


Output:

You are calling method of parent class.
Welcome to Gfg!!
You are inside parent class.


this Keyword in Dart

While super keyword is used to call parent class, this keyword is used to call the class itself.

Advantages of this keyword

  • It can be used to call instance, the current class.
  • It can be used to set the values of the instance variable.
  • It can be used to return the current class instance.

Using this keyword in Dart

Example :


Output:

Welcome to Geeks for Geeks

To know more about this keyword refer this article: Dart - this keyword.

Conclusion

  • Use the keyword super to access variables, methods, and constructors from the parent class.
  • Use this to refer to the instance variables and methods of the current class.
  • Both keywords contribute to better structuring and understanding of class relationships in Dart.
Comment
Article Tags:
Article Tags:

Explore