What will be printed as a result of the following code execution?

public class Test {
    public static void main(String[] args) {
        int i = 1;
        add(i++);
        System.out.println(i);
    }
    
    static void add(int i) {
        i += 2;
    }
}
Explanation
The value of the i variable increases by 1 each time it is transferred to the corresponding method.
A variable with the same name is used inside the add() method, but any actions performed under it do not modify the initial variable.
Java
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback