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