Question: 9 . Consider the following method. public static void f ( int k , int [ ] a , String s ) { int j
Consider the following method.
public static void fint k int a String s
int j k;
int len alength ;
char c;
try
c scharAt;
if k j a;
catch ArrayIndexOutOfBoundsException ex
System.out.printlnarray error";
throw new InternalError;
catch ArithmeticException ex
System.out.printlnarithmetic error";
catch NullPointerException ex
System.out.printlnnull ptr;
finally
System.out.printlnin finally clause";
System.out.printlnafter try block";
Part A
Assume that variable x is an array of int that has been initialized to be of length For each of the following calls to method f say what if anything is printed by f and what, if any, uncaught exceptions are thrown by f
Af xhi;
prints:
throws:
Bf x;
prints:
throws:
Cf x "bye";
prints:
throws:
D f x null;
prints:
throws:
Part B
Why doesn't f need to have a throws clause?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
