What will be the output of the following code?

class Test {
    private int i;
    public void setI(int i) {
      this.i = i;
    }

    public int getI() {
      return i;
    }
}

public class Main {
     private Test t;
     public int getSomeInteger() {
         try {
             return t.getI();
         } finally {
             return 0;
         }
     }

     public static void main(String[] args) throws Exception {
         Main m = new Main();
         System.out.println(m.getSomeInteger());
     }
}
Explanation
The output will be 0, since returning anything from the finally block will override the thrown exception.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback