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