OCA Java SE 8 Exception - OCA Mock Question Exception 10
Question
Which of the following statements are true? (Choose all that apply)
- You can declare a method to return Exception type.
- You can declare subclass of Error to throw in throws part of a method declaration.
- You can declare subclass of Exception to throw in the throws part of a method declaration.
- You can declare subclass of Object to throw.
- You can declare subclass of RuntimeException in the throws part of a method declaration.
Answer
Note
Classes listed in the throws part of a method declaration must extend
java.lang.Throwable.
This includes Error, Exception, and RuntimeException.
Any Java type, including Exception, can be declared as the return type.