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