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

Shared Registry Counter

Mark
< Prev
Next >

A class maintains a static counter used to assign unique identification numbers to each new instance created.

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

public class QuestionTrace {

    public static void main(String[] args) {
        Registry r1 = new Registry();
        Registry r2 = new Registry();
        System.out.print(r1.getId() + "" + r2.getId());
    }
}

class Registry {

    private static int count = 500;
    private int id;

    public Registry() {
        id = count;
        count++;
    }

    public int getId() {
        return id;
    }
}
A

500501

B

501501

C

500500

D

501502

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|