Java OCA OCP Practice Question 1185

Question

Given a method with one of the following return types,

which data type prevents the return statement from being used within the method?

  • A. byte
  • B. String
  • C. void
  • D. None of the above


D.

Note

Options A and B are incorrect because a method with a non-void return type requires that the method return a value using the return statement.

Option C is also incorrect since a method with a void return type can still call the return command with no values and exit the method. Therefore, Option D is the correct answer.




PreviousNext

Related