Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 3: Class Creation
Start Practice TestPractice Test
About Exam
medium Solved by 14 students

Static Variable Shadowing

Mark
< Prev
Next >

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.

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1sailajavadlamani3322 - 200
#2Ishaan.m.kurup23 - 190
#3sgarv251324 - 180
#4suhanakochhar00622 1m 31s 109
#5dinhhoa11 - 100
#6chunxiangxu.cxu11 0m 06s 94
#7busemagngr11 0m 37s 63
#8zgj0731041712 1m 06s 24
#9songqiuhui201201 0m 42s -52
#10psak1211 2m 55s -75
Items per page:
10
1 – 10 of 13
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|