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