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