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