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