В результате работы кода, что будет выведено на экран?

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
Будет выведено 0. Так как если что либо вернуть из блока finally, то любое выброшенное исключение игнорируется.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes