Java OCA OCP Practice Question 1195

Question

Which of the following is a valid method name in Java?

  • A. Go_$A$2()
  • B. have-A()
  • C. new()
  • D. 9enjoyTheMain()


A.

Note

Option A is correct since method names may include the underscore _ character as well as the dollar $ symbol.

There is no rule that requires a method start with a lowercase character.

It is just a practice adopted by the community.

Option B is incorrect because the hyphen - character may not be part of a method name.

Option C is incorrect since new is a reserved word in Java.

Option D is incorrect.

A method name must start with a letter, the dollar $ symbol, or an underscore _ character.




PreviousNext

Related