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