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