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

Shared Reference

Mark
< Prev
Next >

Two variables refer to the same object instance. Changes made via one reference affect the object state observed by the other.

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

class Counter {

    int count;

    Counter(int c) {
        count = c;
    }
}

public class QuestionTrace {

    public static void main(String[] args) {
        Counter c1 = new Counter(10);
        Counter c2 = c1;
        c2.count += 5;
        System.out.println(c1.count);
    }
}
A

0

B

15

C

5

D

10

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|