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