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 Job Counter

Mark
< Prev
Next >

A printer class utilizes a static variable to track the total number of instances created.

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

public class QuestionTrace {

    public static void main(String[] args) {
        Printer p1 = new Printer();
        Printer p2 = new Printer();
        System.out.print(p1.getCount() + "" + p2.getCount());
    }
}

class Printer {

    private static int count = 0;

    public Printer() {
        count++;
    }

    public int getCount() {
        return count;
    }
}
A

22

B

12

C

11

D

21

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|