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