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