Constructors

Let’s learn about a special method through which we can initialize instance variables while creating an instance of a class.

Overview

In Dart, constructors are special functions of a class that are responsible for initializing the instance variables of that class.

A constructor must have the same name as the class it is being declared in and since it is a function, it can be parameterized. However, unlike regular functions, constructors do not have a return value, hence cannot have a return type.

Dart offers multiple types of constructors. In this course, we will be learning about two of them.

  1. Generative Constructor
  2. Named Constructor

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy