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