Friday, August 16, 2019

What is the output of the following code?

Problem statement:
Given the code of java. Find out the output.
  1. public class Test {
  2. static void test() throws RuntimeException {
  3. try {
  4. System.out.println("test");
  5. throw new RuntimeException();
  6. } catch (Exception ex) {
  7. System.out.println("exception");
  8. }
  9. }
  10. public static void main(String[] args) {
  11. try {
  12. test();
  13. } catch (RuntimeException ex) {
  14. System.out.println("runtime");
  15. }
  16.     System.out.println("end");
  17. }
  18. }
Output:
test
exception
end

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...