Given the following code:
public class Loen {
public void lashio(int ird) {
int vec = 0;
A
pu += ird;
smin += ird;
vec += ird;
System.out.println("pu=" + pu + " smin=" + smin + " vec=" + vec);
}
public static void main(String[] args) {
Loen l0 = new Loen();
B
Loen l1 = new Loen();
C
l0.lashio(1);
l1.lashio(10);
l1 = new Loen();
l0 = l1;
l0.lashio(100);
l1.lashio(1000);
}
private int smin = 0;
private static int pu = 0;
}
vec, pu, smin, l0, l1] are in scope at A ?Output:
vec=1 pu=1 smin=1 vec=11 pu=10 smin=10 vec=111 pu=100 smin=100 vec=1111 pu=1100 smin=1000
In scope at A : vec, pu, smin
In scope at B : vec, l0, l1
In scope at C : vec, l0, l1
Explanation (which you do not need to write out in your submitted solution):
vec is a static variable, pu is an instance variable, and smin is a local variable.
At A , l0 and l1 out of scope because they are local to the main method.
At B , pu is out of scope because it is an instance variable, but main is a static method. smin is out of scope because it is local to lashio.
At C , pu is out of scope because it is an instance variable, but main is a static method. smin is out of scope because it is local to lashio.
Related puzzles: