Java OCA OCP Practice Question 1622

Question

Which one of these declarations is a valid method declaration?.

Select the one correct answer.

  • (a) void method1 { /* ... */ }
  • (b) void method2() { /* ... */ }
  • (c) void method3(void) { /* ... */ }
  • (d) method4() { /* ... */ }
  • (e) method5(void) { /* ... */ }


(b)

Note

Only (b) is a valid method declaration.

Methods must specify a return type or must be declared void.

This makes (d) and (e) invalid.

Methods must specify a list of zero or more comma-separated parameters enclosed by parentheses, ( ).

The keyword void cannot be used to specify an empty parameter list.

This makes (a) and (c) invalid.




PreviousNext

Related