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 1 students

Aliased Score Tracking

Mark
< Prev
Next >

A program uses a ScoreKeeper class to manage player points, where two different references are assigned to the same object instance.

What is printed when the following Java program is compiled and run?

class ScoreKeeper {

    private int points;

    public void add(int p) {
        points += p;
    }

    public int getPoints() {
        return points;
    }
}

public class QuestionTrace {

    public static void main(String[] args) {
        ScoreKeeper s1 = new ScoreKeeper();
        ScoreKeeper s2 = s1;
        s1.add(5);
        s2.add(3);
        System.out.print(s1.getPoints());
    }
}
A

3

B

0

C

5

D

8

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

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

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