Constructor

A constructor is a special type of member method that is automatically called when a new object of a class is created. The purpose of the constructor is to initialize the member variables, ensuring that the object is in a valid state upon creation. For example, the constructor for class Person is defined as follows.

def Person(name_, age_) {
    name = name_
    age = age_
}