Our example demonstrates working with structs, which are typed collections of fields that can be used to group data together to form records.
In this example, we’ve created a Person class with name and age fields. We also defined a constructor that initializes the name and sets the age to 42 by default. The newPerson function is used for creating a new Person instance.
To run the program, save the code in a .groovy file and use the groovy command to execute it.
Now that we can run and build basic Groovy programs with classes, let’s learn more about the language.