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 Studentis defined as follows.

def Student(name_, age_, score_) { 
  name = name_
  age = age_
  score = score_
}