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