Consider this Java code for the following questions: public class Test { public
ID: 673939 • Letter: C
Question
Consider this Java code for the following questions:
public class Test {
public static void main(String[] args) {
try {
System.out.println ("statement1");
methodA();
System.out.println ("statement2");
} catch (ExceptionQ ex) {
System.out.println ("statement3");
} finally {
System.out.println ("statement4");
}
System.out.println ("statement5");
}
public static void methodA() {
try {
System.out.println ("statemen6");
methodB();
System.out.println ("statement7");
} catch (ExceptionR ex) {
System.out.println ("statement8");
} finally {
System.out.println ("statement9");
}
System.out.println ("statement10");
}
public static void methodB() {
try {
System.out.println ("statement11");
} catch (ExceptionS ex) {
System.out.println ("statement12");
} catch (ExceptionT ex) {
System.out.println ("statement13");
} finally {
System.out.println ("statement14");
}
System.out.println ("statement15");
}
}
---------------------------------
#1: Which statements will execute if no exceptions are thrown?
#2: Which statements will execute if ExceptionS is thrown before statement 11 in methodB?
#3: Which statements will execute if ExceptionR is thrown before statement 11 in methodB?
#4: Which statements will execute if ExceptionQ is thrown before statement 11 in methodB?
#5: Which statements will execute if ExceptionC is thrown before statement 11 in methodB?
Explanation / Answer
#1: Which statements will execute if no exceptions are thrown?
statement1
statemen6
statement11
statement14
statement15
statement7
statement9
statement10
statement2
statement4
statement5
#2: Which statements will execute if ExceptionS is thrown before statement 11 in methodB?
statement1
statemen6
statement13
statement14
statement15
statement7
statement9
statement10
statement2
statement4
statement5
#3: Which statements will execute if ExceptionR is thrown before statement 11 in methodB?
statement1
statemen6
statement14
statement8
statement9
statement10
statement2
statement4
statement5
#4: Which statements will execute if ExceptionQ is thrown before statement 11 in methodB?
statement1
statemen6
statement14
statement9
statement3
statement4
statement5
#5: Which statements will execute if ExceptionC is thrown before statement 11 in methodB?
statement1
statemen6
statement14
statement9
statement4