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