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