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
hard

Independent Point Trackers

Mark
< Prev
Next >

A Tracker object maintains an instance variable representing its location. Two objects are created to ensure that changes to one do not affect the other.

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

class Tracker {

    private int pos;

    public Tracker(int p) {
        pos = p;
    }

    public void move(int step) {
        pos += step;
    }

    public int getPos() {
        return pos;
    }
}

public class QuestionTrace {

    public static void main(String[] args) {
        Tracker t1 = new Tracker(10);
        Tracker t2 = new Tracker(20);
        t1.move(5);
        System.out.print(t1.getPos() + " " + t2.getPos());
    }
}
A

15 20

B

10 20

C

10 25

D

15 25

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|