Super Keyword in Dart:
In Dart, 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 use to access the data members of parent class when both parent and child have member with same name.
- It is use to prevent overriding the parent method.
- It can be used to call parameterized constructor of parent class.
// To access parent class variables super.variable_name; // To access parent class method super.method_name();
Example #1: Showing the flow of object creation in inheritance.
You are inside Parent constructor!! You are inside Child constructor!!
Example #2: Accessing parent class variables
Geeks for Geeks
Example #3: Accessing parent class methods
You are calling method of parent class. Welcome to Gfg!! You are inside parent class.
This Keyword in Dart:
While super keyword is use to call parent class, this keyword is use to call the class itself.
Advantages of this keyword:
- It can be use to call instance variable of current class.
- It can be use to set the values of the instance variable.
- It can be use to return the current class instance.
Using this keyword in Dart –
Welcome to Geeks for Geeks
- Super Constructor in Dart
- Dart - Const And Final Keyword
- Dart - Static Keyword
- Dart - this keyword
- Dart - Classes And Objects
- Dart - Loop Control Statements (Break and Continue)
- Instance and class methods in Dart
- Getter and Setter Methods in Dart
- Dart - Finding Minimum and Maximum Value in a List
- HTML Document Object Model and Dart Programming
- Variables and Keywords in Dart
- What is Lexical scope and lexical closures in Dart
- Dart - Getters and Setters
- Difference Between DART and C++
- Dart - Dates and Times
- Upload and Retrieve Images on MongoDB using Dart in Flutter
- Difference Between Golang and Dart
- How to Combine Lists in Dart?
- Basics of Numbers in Dart
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.