| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
Share
About Exam
medium Solved by 20 students
Static Variable Shadowing
< Prev
Next >

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.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1sailajavadlamani3322 0m 00s 200
#2Ishaan.m.kurup23 0m 00s 190
#3sgarv251324 0m 00s 180
#4suhanakochhar00622 1m 31s 109
#5dinhhoa11 0m 00s 100
#6songqiuhui201201 0m 42s -52
#7psak1211 2m 55s -75
#8y.seong202701 2m 01s -131
#9tfvhygdj12 11m 47s -617
#10jaydenandjayden66624 4h 55m -17,570
Items per page:
10
1 – 10 of 10

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy