Q. Which of the following is the correct syntax for declaring a method in Java?
β
Correct Answer: (B)
public void myMethod() { System.out.println(“Hello”); }
Explanation: The syntax for declaring a method in Java is to use an access modifier (such as public or private), followed by the return type of the method (such as void or int), the name of the method, and any parameters in parentheses.