In Mala Gupta's oca java se 8 Programmer I Certification Guide, sample exam question 3.4 (page 214), it is asked whether the following statement is true:
'A method should accept at least one method argument or define its return type'
The answer is that this statement is false.
The first part of this statement is false, but I thought the second part is true. After all, a return type should always be defined for a method, right? Or is void not considered a return type? What is the reason behind this statement being false?
Thank you all in advance

Charles O'Leary wrote:
These two fragments are not substitutes for each other. At least, that's my "reading into" this statement.The first part of this statement is false, but I thought the second part is true.
After all, a return type should always be defined for a method, right?
![]()
I know they're not substitutes. But if the first part is false, and the second part is true, then how can the statement as a whole be false?
Charles O'Leary wrote:Unfortunately, I don't have that book. Could you please post the answer? My interpretation is that the question appears to be asking if a valid method's signature will either have A or B. Where A = ' accept at least one method argument' , while B = ' define its return type'. Again, I don't own that book unfortunately, but that's my interpretation of the question. So even IF they both (A & B) were true, constructing a valid method signature requires a lot of other rules to be followed. Does that help?
All the book says about this question is "There's no constraint on the number of arguments that can be passed to a method, regardless of whether the method returns a value".
I agree with you, that's how I interpret the question as well. Which is why it's so strange to be that the statement is incorrect.
-
1
-
-
-
-
Paragraph 8.4 is about method declarations, and paragraph 8.4.5 specifically about method results. The JLS says:
JLS 8.4.5 wrote:
The result of a method declaration either declares the type of value that the method returns (the return type), or uses the keyword void to indicate that the method does not return a value.
This sentence clearly says that there are two possibilities for the result:
void is not a return type. Indeed, void is not a type at all, for example you cannot declare variables of the type void.
So the second part of the statement is also false. A method is not required to have a return type; if it doesn't return anything, you use the keyword void (which is not a return type!) to indicate that.
Jesper de Jong wrote:The ultimate authority for such questions about the details of the language is the Java Language Specification.
Paragraph 8.4 is about method declarations, and paragraph 8.4.5 specifically about method results. The JLS says:
JLS 8.4.5 wrote:
The result of a method declaration either declares the type of value that the method returns (the return type), or uses the keyword void to indicate that the method does not return a value.
This sentence clearly says that there are two possibilities for the result:
the name of the return type the keyword void
void is not a return type. Indeed, void is not a type at all, for example you cannot declare variables of the type void.
So the second part of the statement is also false. A method is not required to have a return type; if it doesn't return anything, you use the keyword void (which is not a return type!) to indicate that.
Shane, I agree with Jesper 100%. Hopefully, that doesn't add to any confusion that you/one may have. When there is no return type for a method, in the place where one would normally put the return type, one would instead put "void". If I'm a new programmer looking at this, I'm thinking: HUH? It's either a return type OR it is not ... and this is just a little nuts. As a forewarning, "word problems" may sometimes have this "ambiguity". Context is king.
To button this up, it seems as if you were thinking of this as a Java keyword or, where only one side had to be true for the entire statement to be true. While a second "interpretation" may be asking if there is a difference between half a dozen and 6 eggs.
At the end of the day if nothing else, I hope you walk away knowing that constructing a valid method signature is much more than a return type and an input parameter. Many other Java rules must be adhered to.
Jesper de Jong wrote:The ultimate authority for such questions about the details of the language is the Java Language Specification.
Paragraph 8.4 is about method declarations, and paragraph 8.4.5 specifically about method results. The JLS says:
JLS 8.4.5 wrote:
The result of a method declaration either declares the type of value that the method returns (the return type), or uses the keyword void to indicate that the method does not return a value.
This sentence clearly says that there are two possibilities for the result:
the name of the return type the keyword void
void is not a return type. Indeed, void is not a type at all, for example you cannot declare variables of the type void.
So the second part of the statement is also false. A method is not required to have a return type; if it doesn't return anything, you use the keyword void (which is not a return type!) to indicate that.
It makes sense to me now. Excellent advice as well, to consult the JLS.
Thank you Jesper and Charles for your insights!