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