Saturday, August 17, 2019

what will happen when you run the following code?

Problem statement:
Given the java code. what will be 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. throw new RuntimeException();
  14. } catch (RuntimeException ex) {
  15. System.out.println("runtime");
  16. System.out.println("end");
  17. }
  18. }
  19. }
Output:
test
exception
runtime
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...