nerdexam
Oracle

1Z0-803 · Question #54

You are writing a method that is declared not to return a value. Which two are permitted in the method body?

The correct answer is A. omission of the return statement D. return;. Any method declared void doesn't return a value. It does not need to contain a return statement, but it may do so. In such a case, a return statement can be used to branch out of a control flow block and exit the method and is simply used like this:

Working with Methods and Encapsulation

Question

You are writing a method that is declared not to return a value. Which two are permitted in the method body?

Options

  • Aomission of the return statement
  • Breturn null;
  • Creturn void;
  • Dreturn;

How the community answered

(28 responses)
  • A
    93% (26)
  • B
    4% (1)
  • C
    4% (1)

Explanation

Any method declared void doesn't return a value. It does not need to contain a return statement, but it may do so. In such a case, a return statement can be used to branch out of a control flow block and exit the method and is simply used like this:

Topics

#void methods#return statement#method signature

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice