Saturday, May 11, 2019

what will happen when you run the following code?

Problem statement:
what is the output for the following code?
  1. class ExecutionTen {
  2.     public void talk() {}
  3. }
  4. public class ExecutionNine {
  5.     public static void main(String[] args) {
  6.         ExecutionTen t = null;
  7.         try {
  8.             t.talk();
  9.         } catch (NullPointerException e) {
  10.             System.out.println("This is NullPointerException !");
  11.         } catch (Exception e) {
  12.             System.out.println("This is an Exception !");
  13.         }
  14.         System.out.println("Everything went fine !");
  15.     }
  16. }
Output:
This is NullPointerException !
Everything went fine !

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...