Methods in Groovy are Defined with a return type or with the def keyword. If a method is defined with specific type, then it should return the value of that type only.
Factorial of 5 is 120
In the above example, I defined a method ‘fact’ which takes an Integer as input and return an integer value as output.
If you make the return type of the method as def, then you can return value of any type.