What will the following code print out?

public class Test {
    int i = 1;

    void add(int i) {
        i += i;

    public static void main(String args[]) {
        Test t = new Test();
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
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes