Multiple choice technology programming languages

package exceptions; public class TestException2 { static double testException(int x, int y) { return (x/y); } public static void main(String[] args) { try { double p = testException(10,5); System.out.println("p = "+p); } catch(Exception e) { System.out.println("Exception happened "+e.getMessage()); return; } finally { System.out.println("In finally"); } } }

  1. p = 2.0

  2. Compiler Error

  3. Exception

  4. p = 2.0 In finally

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

The division 10 / 5 returns 2.0 (as double). Since no exception occurs, the catch block is bypassed. However, the finally block is guaranteed to execute regardless of whether an exception is thrown, appending 'In finally' to the output. Thus, the program prints both lines sequentially.