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
easy

Independent Counter States

Mark
< Prev
Next >

Consider a system where two objects track their own unique integer values independently using a shared class definition.

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

public class QuestionTrace {

    public static void main(String[] args) {
        Counter c1 = new Counter(10);
        Counter c2 = new Counter(20);
        c1.increment();
        System.out.print(c1.getValue() + "" + c2.getValue());
    }
}

class Counter {

    private int value;

    public Counter(int start) {
        value = start;
    }

    public void increment() {
        value++;
    }

    public int getValue() {
        return value;
    }
}
A

1021

B

1120

C

1020

D

1121

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|