5.6) What happens if both a catch and a finally block define return statement?


public class MultipleReturn {
int getInt() {
try {
String[] students = { "Harry", "Paul" };
System.out.println(students[5]);
} catch (Exception e) {
return 10;
} finally {
return 20;
}
}
}
public class TestMultipleReturn {
public static void main(String[] args) {
MultipleReturn var = new MultipleReturn();
System.out.println(var.getInt());
}
}
Previous5.5) Will a finally block execute even if the catch block defines a return statement?Next5.7) What happens if a finally block modifies the value returned from a catch block?
Last updated
Was this helpful?