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