Java Foundations — Question 29
Which statement is true about a Java method?
Answer options
- A. It must be declared with an access modifier.
- B. It cannot be defined within another method.
- C. It must accept a parameter and return a value.
- D. It cannot be defined as static final.
Correct answer: B
Explanation
The correct answer is B because in Java, methods cannot be nested within other methods. Option A is incorrect because while it is common to declare methods with an access modifier, it is not mandatory. Option C is also wrong since a method can be defined without parameters or a return value. Option D is incorrect; a method can be declared as static, but the term 'static final' is not applicable to methods.