Static Variable Shadowing
Consider the Configuration class shown below. The update method is intended to change the value of the static variable value. Which of the following best explains why the method does not work as intended?
public class Configuration {
public static int value = 5;
public void update(int newVal) {
int value = newVal;
}
public int getValue() {
return value;
}
}
A
The update method should be declared static to modify a static variable.
B
It declares a new local variable that shadows the static field, so the static value is never updated.
C
It does not include an else statement to handle alternate cases.
D
It fails to pass the new value by reference, so the update does not persist.
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | sailajavadlamani33 | 2 | 2 | 0m 00s | 200 |
| #2 | Ishaan.m.kurup | 2 | 3 | 0m 00s | 190 |
| #3 | sgarv2513 | 2 | 4 | 0m 00s | 180 |
| #4 | suhanakochhar006 | 2 | 2 | 1m 31s | 109 |
| #5 | dinhhoa | 1 | 1 | 0m 00s | 100 |
| #6 | chunxiangxu.cxu | 1 | 1 | 0m 06s | 94 |
| #7 | zgj07310417 | 1 | 2 | 1m 06s | 24 |
| #8 | songqiuhui2012 | 0 | 1 | 0m 42s | -52 |
| #9 | psak12 | 1 | 1 | 2m 55s | -75 |
| #10 | y.seong2027 | 0 | 1 | 2m 01s | -131 |
Items per page:
10
1 – 10 of 12
