147k views
3 votes
What is displayed on the console when running the following program? class Test { public static void main(String[ ] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2/i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } } }

1 Answer

5 votes

Answer:

This program will display "Welcome to Java" two times and then followed by "End of the block"

Step-by-step explanation:

Here, the following program written in Java Programming Language.

Firstly, the class is defined "test" after that, the main method is defined "public static void main(String[ ] args)" then, set the try block and inside the try block print "Welcome to Java" then, two integer variable is declared "i" to 0 and "y" to 2/i then, again print "Welcome to Java" then close the try block.

Then, set the catch block and pass the exception "RuntimeException ex" inside the catch block again print "Welcome to Java" and close it.

Then, set finally block and inside it print "End of the block" and close it.

User Marczoid
by
8.0k points