Constructors

A constructor is a special method that runs when an object is created. It initializes the object.

class Person {
  String name;

  Person(String personName) {
    name = personName;
  }
}

You can have multiple constructors using constructor overloading.

← PrevNext →