5.7) What happens if a finally block modifies the value returned from a catch block?

public class MultipleReturn {
int getInt() {
int returnVal = 10;
try {
String[] students = { "Harry", "Paul" };
System.out.println(students[5]);
} catch (Exception e) {
System.out.println("About to return :" + returnVal);
return returnVal;
} finally {
returnVal = returnVal + 10;
System.out.println("Return value is now :" + returnVal);
}
return returnVal;
}
}


Problem 1: (Explain the output)
Output:

Problem 2: (Explain the output)
Output:

Problem 3:
Previous5.6) What happens if both a catch and a finally block define return statement?Next5.8) Can a try block be followed only by a finally block?
Last updated
Was this helpful?