| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
medium Solved by 21 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
Report Question

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
#6chunxiangxu.cxu11 0m 06s 94
#7zgj0731041712 1m 06s 24
#8songqiuhui201201 0m 42s -52
#9psak1211 2m 55s -75
#10y.seong202701 2m 01s -131
Items per page:
10
1 – 10 of 12
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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