What will be shown in console after following code compiles (choose all numbers that will be printed):

public class ArrTest {
    public static void main(String[] X){
        print(new int[] { 1, 2, 3, 4 });
        print(new Long[] { 1l, 2l, 3l, 4l });
    }
    static void print(Long i){
        System.out.print(1);
    }
    static void print(Object i){
        System.out.print(2);
    }
    static void print(Object... i){
        System.out.print(3);
    }
    static void print(long[] i){
        System.out.print(4);
    }
    static void print(Integer... i){
        System.out.print(5);
    }
    static void print(Number... i){
        System.out.print(6);
    }
}
Explanation
Right answers is 2 and 6.
At print(new int[] { 1, 2, 3, 4 }) call, next method will be used: print(Object i), because array is an Object.
At print(new Long[] { 1l, 2l, 3l, 4l }) call, print(Number... i) will be used because Long[] in java extends Number[]

Следи за CodeGalaxy

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

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