From the course: Learning Groovy

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Creating and using a class

Solution: Creating and using a class - Groovy Tutorial

From the course: Learning Groovy

Solution: Creating and using a class

(upbeat music) - [Instructor] Let's talk about the solution for this challenge. I will guide you through the functionality step by step. You can find the complete solution in your exercise folder, but feel free to download and enhance the code yourself. First, we'll create a new Groovy class called calculator. To do so, we'll go over to the source folder, bring up the context menu and select New, Groovy Class. And here we'll enter the name of the class and press Enter. Now we have a new class alongside the main class that already existed here. So now let's add these specific methods, we'll start by the add method. And the return type of that add method should be an integer, so we'll define that first. We'll add the name of the method and then two different parameters, we'll call them a and b for now. And then as the body, the actual implementation of the method, we simply say a plus b, pretty straightforward. We can do…

Contents