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.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback