What will the following code print out?

public class Test {
    int i = 1;

    void add(int i) {
        i += i;
        System.out.println(i);
    }

    public static void main(String args[]) {
        Test t = new Test();
        t.add(5);
    }
}
Explanation
Inside the add method, we work only with the method i parameter, since in order to access a class variable i (especially in the case of coincidence of names) "this" keyword should be used.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Cosmo
Зареєструйся Зараз
або Підпишись на майбутні тести