Within the body of the method, you use the return operator to return the value. Any method that is not declared void must contain a return statement. The isEmpty method returns either the boolean value true or false , depending on the outcome of a test. A compiler error results if you try to write a method in which the return value doesn't match the return type. The isEmpty method returns a primitive type.
Methods also can return a reference type.
This can be a source of confusion, so let's look at this more closely. The returnANumber method can return an ImaginaryNumber but not an . You also can use interface names as return types. In this case, the object returned must implement the specified interface. A Method's Name Java supports method name overloading so that multiple methods can share the same name.