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