What is the result of the following program execution?

class Test2 {
    static int N(Integer x) {
        return x;
    }
}

public class Test {
    static int M(Integer v){
        return v;
    }
    public static void main(String[] args){
        Integer x = M(100);     // 1
        Integer z = N(100);     // 2
        System.out.println(x + " " + z);
    }
}
Explanation
In line 1, the method will be found and 100 will be autoboxed to Integer, the method will return an int, hence the object will be autounboxed, but x is an Integer object and 100 will be autoboxed again into Integer.
A compilation error will occur in line number 2 because the method N(int) will not be found.

Следи за CodeGalaxy

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

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