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