Which statement is true about a Java method?
Which statement is true about a Java method?
A Java method cannot be defined within another method. Methods are defined within a class, but not inside each other. This is a fundamental aspect of the structure of Java code. Therefore, the statement that a Java method cannot be defined within another method is true.
A is not correct, because if no modifier is added to method, by default java will add 'protected' modifier. B is the correct answer.
In Java, every method must be declared with an access modifier, which defines the visibility of the method. The access modifiers include public, private, protected, and package-private (default). The choice of access modifier determines where the method can be accessed from.
B is correct. will result in compile time error
B is the correct answer as we cannot have a method inside another method.