What will the following code display?

class Quizful {
    private static int count = 0;
    private final int id = ++count;

    private void print() {
        System.out.println(id);
    }

    public void printOther(Quizful other) {
        other.print();
    }
    public static void main(String[] args) {
        Quizful one = new Quizful();
        Quizful two = new Quizful();
        two.printOther(one);
    }    
}
Explanation
Two objects of Quizful class will be created, first with field id = 1 and second with field id = 2. A reference to object 'one' will be passed to the printOther() method of object 'two'. Then print() of object 'one' will be called and 1 will be printed.

Следи за CodeGalaxy

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

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