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.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести