Static Variable Shadowing
What is the mistake in the update method of the Configuration class?
public class Configuration {
public static int value = 5;
public void update(int newVal) {
int value = newVal; // Error: A local variable 'value' is declared, shadowing the static variable.
}
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 | songqiuhui2012 | 0 | 1 | 0m 42s | -52 |
| #7 | psak12 | 1 | 1 | 2m 55s | -75 |
| #8 | y.seong2027 | 0 | 1 | 2m 01s | -131 |
| #9 | tfvhygdj | 1 | 2 | 11m 47s | -617 |
| #10 | jaydenandjayden666 | 2 | 4 | 4h 55m | -17,570 |
Items per page:
10
1 – 10 of 10
APFIVE