mercoledì 27 marzo 2013

Q31

A method doSomething () that has no exception handling code is modified to trail a method that throws a checked exception.
Which two modifications, made independently, will allow the program to compile?

A.
Catch the exception in the method doSomething().
B.
Declare the exception to be thrown in the doSomething() method signature.
C.
Cast the exception to a RunTimeException in the doSomething() method.
D.
Catch the exception in the method that calls doSomething().
Risposta : la situazione è questa :
public class Main {
       void doSomething() {
             metodoConEccezione();
       }
       void metodoConEccezione() throws Exception {
       }
.Ci sono due possibili soluzioni, o circondare la chiamata al metodo con un try catch oppure inserire il throws anche nel doSomething() . In figura si vedono entrambi i metodi che risolvono, ciascuno preso singolarmente, il problema.
 
Quindi le risposte possibili sono A e B.

Nessun commento:

Posta un commento