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