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