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