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