Home » Oracle » 1z0-803 » Should other code be added in the dosomething() method for it to compile and execute?
An unchecked exception occurs in a method dosomething()
Should other code be added in the dosomething() method for it to compile and execute?
A. The Exception must be caught
B. The Exception must be declared to be thrown.
C. The Exception must be caught or declared to be thrown.
D. No other code needs to be added.
Correct Answer: D
Explanation/Reference:
Explanation:
Because the Java programming language does not require methods to catch or to specify unchecked exceptions (RuntimeException, Error, and their subclasses), programmers may be tempted to write code that throws only unchecked exceptions or to make all their exception subclasses inherit from RuntimeException. Both of these shortcuts allow programmers to write code without bothering with compiler errors and without bothering to specify or to catch any exceptions. Although this may seem convenient to the programmer, it sidesteps the intent of the catch or specify requirement and can cause problems for others using your classes.
Download Printable PDF. VALID exam to help you PASS.
|
|