Given the following code:
public class Ossu {
private int woau = 0;
private static int mo = 0;
public void pseCemi(int me) {
A
int truc = 0;
mo += me;
truc += me;
woau += me;
System.out.println("mo=" + mo + " truc=" + truc + " woau=" + woau);
}
public static void main(String[] args) {
Ossu o0 = new Ossu();
B
Ossu o1 = new Ossu();
o0.pseCemi(1);
o1.pseCemi(10);
o0.pseCemi(100);
o0 = new Ossu();
o1 = o0;
o1.pseCemi(1000);
C
}
}
woau, mo, truc, o0, o1] are in scope at A ?Output:
woau=1 mo=1 truc=1 woau=11 mo=10 truc=10 woau=111 mo=100 truc=101 woau=1111 mo=1000 truc=1000
In scope at A : woau, truc, mo
In scope at B : woau, o0, o1
In scope at C : woau
Explanation (which you do not need to write out in your submitted solution):
woau is a static variable, truc is an instance variable, and mo is a local variable.
At A , o0 and o1 out of scope because they are local to the main method.
At B , truc 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 pseCemi.
At C , o0 and o1 are out of scope because they are not declared yet. truc 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 pseCemi.
Related puzzles: