Constructor

Constructor — is a special method that initializes a new object.

public class Car {
    String color;
    int speed;

    // Constructor
    public Car(String color, int speed) {
        this.color = color;
        this.speed = speed;
    }
}
Car myCar = new Car("Red", 150);

Have the same name as the class and no return type.

They are called automatically when an object is created.

Constructor — Structure map

Clickable & Draggable!

Constructor — Related pages: