Given the following code:
public class Repdud {
public void grict(int as) {
A
int osm = 0;
joso += as;
osm += as;
comi += as;
System.out.println("joso=" + joso + " osm=" + osm + " comi=" + comi);
}
private static int comi = 0;
private int joso = 0;
public static void main(String[] args) {
Repdud r0 = new Repdud();
B
Repdud r1 = new Repdud();
C
r0.grict(1);
r1.grict(10);
r0.grict(100);
r1 = r0;
r0 = new Repdud();
r1.grict(1000);
}
}
comi, joso, osm, r0, r1] are in scope at A ?Output:
comi=1 joso=1 osm=1 comi=10 joso=10 osm=11 comi=101 joso=100 osm=111 comi=1101 joso=1000 osm=1111
In scope at A : osm, comi, joso
In scope at B : osm, r0, r1
In scope at C : osm, r0, r1
Explanation (which you do not need to write out in your submitted solution):
osm is a static variable, comi is an instance variable, and joso is a local variable.
At A , r0 and r1 out of scope because they are local to the main method.
At B , comi is out of scope because it is an instance variable, but main is a static method. joso is out of scope because it is local to grict.
At C , comi is out of scope because it is an instance variable, but main is a static method. joso is out of scope because it is local to grict.
Related puzzles: