D

Deepak Sahoo • 10.78K Points
Tutor II

Q. Which of the following is the correct syntax for declaring a method in Java?

  • (A) void myMethod() { System.out.println(“Hello”); }
  • (B) public void myMethod() { System.out.println(“Hello”); }
  • (C) myMethod() { System.out.println(“Hello”); }
  • (D) public myMethod() { System.out.println(“Hello”); }
  • Correct Answer - Option(B)
  • Views: 123
  • Filed under category JAVA

Explanation by: Deepak Sahoo
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.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.


Question analytics