Java OCA OCP Practice Question 1080

Question

Which of the following statements are true? (Choose all that apply)

  • A. You can declare a method with Exception as the return type.
  • B. You can declare any subclass of Error in the throws part of a method declaration.
  • C. You can declare any subclass of Exception in the throws part of a method declaration.
  • D. You can declare any subclass of Object in the throws part of a method declaration.
  • E. You can declare any subclass of RuntimeException in the throws part of a method declaration.


A, B, C, E.

Note

Classes listed in the throws part of a method declaration must extend java.lang.Throwable.

This includes Error, Exception, and RuntimeException.

Arbitrary classes such as String can't go there.

Any Java type, including Exception, can be declared as the return type.

This will simply return the object rather than throw an exception.




PreviousNext

Related