| preferred AP College board partner for AP classes
AP Computer Science A/Unit 2: Using Objects
Start Practice TestPractice Test
About Exam
medium Solved by 10 students
Static Variable in a Constructor
< Prev
Next >

What is printed as a result of executing the following code segment?

public class Counter {
    public static int count = 0;
    public Counter() {
        count++;
    }
    public static int getCount() {
        return count;
    }
}

public class Main {
    public static void main(String[] args) {
        int count = 5;
        new Counter();
        Counter c = new Counter();
        System.out.println(c.getCount());
    }
}
A

7

B

0

C

2

D

5

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki12 0m 00s 90
#2sailajavadlamani3314 0m 00s 70
#3richa.tuli11 1m 18s 22
#4raufyildirim9501 2m 37s -167
#5liuwilliam07241014 4m 43s -213
#6zgj0731041712 6m 02s -272
#7y.seong202701 5m 02s -312
#8lsj0803092214 9m 31s -501
#9chunxiangxu.cxu12 9m 54s -504
#10jeonsaw172333 14m 59s -599
Items per page:
10
1 – 10 of 10
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy