I thought only functions had return statements since they were explicitly called whereas methods are implicitly called on the class. However, I have seen examples of code where a method has a return statement. Is this conventional? Also, am I wrong in saying that only functions return values, and are methods having return statements a standard convention across multiple languages of only OOP languages?
-
1Java only has methods (some of them `static`). All non methods not declared with return type `void` can return a value, and most do (but they may loop infinitely or throw an exception instead). – Jeffrey Bosboom Oct 04 '14 at 00:29
-
This might be good source to understand further: http://stackoverflow.com/questions/155609/what-is-the-difference-between-a-method-and-a-function – denden130 Oct 04 '14 at 00:34
4 Answers
A method is a function that is associated with an object (or class). So yes, they can return values, or not.
Also - trying things out yourself and/or reading documentation is a much better way to learn than asking us as soon as you get stuck! ;)
Here is Oracle's documentation for defining methods.

- 1,553
- 13
- 22
The post contains incorrect assumptions. For starters Java only has "methods (in this context), even if static. Given this it is trivially true that methods at large in Java can return a value.
Now, as an example1, for an equivalency with a language like VB.NET (which derives from BASIC),
A method that returns a value is a "Function Procedure" (BASIC lingo) - these methods return a value and can then be used as an appropriately-typed expression. They must contain a return
statement on all possible code-execution paths.
A method that has a void
return type is a "Sub Procedure" (BASIC lingo) - these methods do not (and cannot) return a value. Such methods may only be called as statements.
1 The terms "function", "procedure", and "subroutine", eg, are highly dependent upon language/context which is why the above is prefaced. As such, correct Java-terminology dictates using "methods [returning some value upon completion]" and "void methods" to describe the difference - although I find that "function" is still used colloquially (in my circles) when describing the operation of "computing a value without side effects" or when such is supplied as a higher-order argument (eg. lambdas).

- 60,010
- 15
- 145
- 220
I think this is problems of theory. Let me put clear some points.
Before OOP
- procedures was a bits of programs for do someting
- functions was a bits of programs for do someting and return values, like Math f(x) = x*y+E2
After OOP
- procedures and functions are called methods and is equal if they return or not some value.
PD: Also we have methods:
- with firm: function A(b,x) { ... }
- without firm: function A() { ... }
- anoimate: function () { ... }
Methods can have return statements as long as the return type is not void. When you define the method, you can make the method public or private, static or not static, choose the return type (byte, short, int, long, float, double, boolean, char), name the method, and define the inputs.
`public static returnType methodName(input) {
// body
}`