1Z0-811 · Question #4
Which statement is true about a Java method?
The correct answer is B. It cannot be defined within another method. In Java, methods cannot be defined inside other methods - this is a core language constraint that distinguishes Java from languages like JavaScript or Python that support nested functions. Access modifiers (A) are optional; a method with no modifier gets package-private access…
Question
Options
- AIt must be declared with an access modifier.
- BIt cannot be defined within another method.
- CIt must accept a parameter and return a value.
- DIt cannot be defined as static final.
How the community answered
(34 responses)- A3% (1)
- B91% (31)
- D6% (2)
Explanation
In Java, methods cannot be defined inside other methods - this is a core language constraint that distinguishes Java from languages like JavaScript or Python that support nested functions. Access modifiers (A) are optional; a method with no modifier gets package-private access by default. Parameters and return values (C) are also optional - void methods return nothing and many methods take no parameters. A method can absolutely be declared static final (D), which is common when you want a class-level method that cannot be overridden.
Memory tip: Think of Java methods as "first-class citizens of classes, not of other methods" - they live at the class level only, unlike local variables which can be nested anywhere inside a method body.
Topics
Community Discussion
No community discussion yet for this question.