What will be the result of compilation and execution of the following code?

public class Test {
    public static void main(String [] a) {
        int [] b = { 1,2,3,4,5 };
        System.out.println("a[2]=" + a[2]);
    }
}
Explanation
Got you! Array named 'b' is declared and initialized in this code but array named 'a' is used. Therefore, ArrayIndexOutOfBoundsException will be thrown while trying to access a[2], because array 'a' is empty.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты