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