Given the following code:
public class Chepwi {
private int om = 0;
public void bloasm(int qek) {
int tiss = 0;
A
tiss += qek;
uc += qek;
om += qek;
System.out.println("tiss=" + tiss + " uc=" + uc + " om=" + om);
}
private static int uc = 0;
public static void main(String[] args) {
B
Chepwi c0 = new Chepwi();
Chepwi c1 = new Chepwi();
C
c0.bloasm(1);
c1.bloasm(10);
c1 = new Chepwi();
c0.bloasm(100);
c0 = c1;
c1.bloasm(1000);
}
}
om, tiss, uc, c0, c1] are in scope at A ?Output:
om=1 tiss=1 uc=1 om=10 tiss=11 uc=10 om=100 tiss=111 uc=101 om=1000 tiss=1111 uc=1000
In scope at A : tiss, uc, om
In scope at B : tiss, c0
In scope at C : tiss, c0, c1
Explanation (which you do not need to write out in your submitted solution):
tiss is a static variable, uc is an instance variable, and om is a local variable.
At A , 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. uc is out of scope because it is an instance variable, but main is a static method. om is out of scope because it is local to bloasm.
At C , uc is out of scope because it is an instance variable, but main is a static method. om is out of scope because it is local to bloasm.
Related puzzles: