Menu
Question Index
...

What will be the output of the following program?

public class ForForever {
    static int i = 0;

    public static void main(String[] args) {
        for (int i = 0; check(i); i++) {
            System.out.print(i + "~" + ForForever.i + ",");
        }
    }

    private static boolean check(int j) {
        i = j;
        return i < 3;
    }
}


0~0,1~0,2~0,
0~0,1~1,2~2,
Some other output
Compilation Error
Goes into infinite loop

Doubts

Problems

Topic: Static Keyword In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App