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