Accenture Accenture Primer Practice Question
Predict the output What will be the output for the given code snippet startprogram import java.util.Scanner; public class Main{ public static void throwit(){ System.out.println("throwit"); throw new RunTimeException(); } public static void main(String[] args){ try{ System.out.println("Hello"); throwit(); }catch(Exception re){ System.out.println("Caught"); }finally{ System.out.println("Finally"); } System.out.println("After"); } }Answer options
A
Hello
Output will be HELLO THROWIT CAUGHT FINALLY
throwit
Caught
Finally
After
B
Finally
After
C
CompileTimeError
D
throwit
Caught
After
Finally
1/31/24, 4:20 PM AWS Cloud Arch Design - PostQuiz: Attempt review
Correct answer: Hello Output will be HELLO THROWIT CAUGHT FINALLY throwit Caught Finally After
Explanation
Execution: 'Hello' printed, throwit() called printing 'throwit' then throwing RuntimeException, caught by catch(Exception) printing 'Caught', finally block prints 'Finally', then 'After' is printed. Option 0 shows the full correct sequence.