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