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