Dart Super Constructor

In this tutorial you will learn about the Dart Super Constructor and its application with practical example.

Dart Super Constructor

A subclass inherits the variables and methods from its superclass, but the superclass constructor is not inherited in the subclass. The superclass constructors can only be invoked from subclass constructors using the super() constructor. The super() constructor allows a subclass constructor to explicitly call the no-arg and parameterized constructor of superclass.

Table Of Contents

Syntax:-

Implicit super:-

When an object of subclass is created using the new keyword, it invokes the subclass constructor which implicitly invokes the parent class’s default (no-arg constructor) constructor. If no parameters are defined in a superclass constructor, you can bypass the call to super() in your subclass.

Example:-

Output:-

dart_implicit_super_constructor_keyword_example

Explicit super:-

If the constructor in superclass takes arguments then we are required to use parameterized super() method in subclass constructor to invoke parameterized constructor of superclass and pass the requested arguments.

Example 1:-

Output 1:-

dart_parameterized _super_constructor_keyword_example

Example 2:-

Output:-

dart_super_constructor_example

In this tutorial we have learn about the Dart Super Constructor and its application with practical example. I hope you will like this tutorial.