Question: 9 . Consider the following method. public static void f ( int k , int [ ] a , String s ) { int j

9. Consider the following method.
public static void f(int k, int[] a, String s)
{
int j =1/ k;
int len = a.length +1;
char c;
try
{
c = s.charAt(0);
if (k ==10) j = a[3];
}
catch (ArrayIndexOutOfBoundsException ex)
{
System.out.println("array error");
throw new InternalError();
}
catch (ArithmeticException ex)
{
System.out.println("arithmetic error");
}
catch (NullPointerException ex)
{
System.out.println("null ptr");
}
finally
{
System.out.println("in finally clause");
}
System.out.println("after try block");
}
Part A.
Assume that variable x is an array of int that has been initialized to be of length 3. 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.
A.f(0, x,"hi");
prints:
throws:
B.f(10, x,"");
prints:
throws:
C.f(10, x, "bye");
prints:
throws:
D. f(10, 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!