A local variable versus a static field across calls
Predict the outputEasy-MediumJava only
public class Main {
static int calls = 0;
static int next() {
int local = 0;
local++;
calls++;
return local * 10 + calls;
}
public static void main(String[] args) {
System.out.println(next());
System.out.println(next());
System.out.println(next());
}
}
This question is part of Pro+
Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.