Declaration
The return type of a method is written to the left of the name of the method.
To have a method which returns an int
, you write int methodName
.
int returnsEight() {
return 8;
}
To have a method with returns a String
, you write String methodName
.
String getName() {
return "bob";
}
And so on for any type in Java.