Given the following code:
public class LolNoidper {
public void hirhen(int gran) {
int ias = 0;
sqe += gran;
nish += gran;
ias += gran;
System.out.println("sqe=" + sqe + " nish=" + nish + " ias=" + ias);
A
}
private static int nish = 0;
public static void main(String[] args) {
LolNoidper l0 = new LolNoidper();
B
LolNoidper l1 = new LolNoidper();
C
l0.hirhen(1);
l1 = l0;
l1.hirhen(10);
l0 = l1;
l0.hirhen(100);
l1.hirhen(1000);
}
private int sqe = 0;
}
ias, sqe, nish, l0, l1] are in scope at A ?Output:
ias=1 sqe=1 nish=1 ias=11 sqe=11 nish=10 ias=111 sqe=111 nish=100 ias=1111 sqe=1111 nish=1000
In scope at A : sqe, ias
In scope at B : sqe, l0, l1
In scope at C : sqe, l0, l1
Explanation (which you do not need to write out in your submitted solution):
sqe is a static variable, ias is an instance variable, and nish is a local variable.
At A , nish is out of scope because it is not declared yet. l0 and l1 out of scope because they are local to the main method.
At B , ias is out of scope because it is an instance variable, but main is a static method. nish is out of scope because it is local to hirhen.
At C , ias is out of scope because it is an instance variable, but main is a static method. nish is out of scope because it is local to hirhen.
Related puzzles: