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