DRAFT
VoidMethodReturnsValue
Misconception:
A method that has the return type void
can contain a return statement that returns a value.
Incorrect
A method with void return type can return a value
Correct
A method with void return type cannot return a value
CorrectionHere is what's right.
Here is what's right.
If a method’s return type is void
, then the method cannot return any value.
It could be that this misconception appears because students first learned pure functional programming, where every function would return a value.
Example occurrence of this misconception:
class C {
private int field;
public void modify(int value) {
return field + value; // believes "return" means "do what the name of the method says"?
}
}
Language
Java