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

What is the output of the code regarding the Counter’s static count?

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

0

B

5

C

2

D

7

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki12 0m 00s 90
#2sailajavadlamani3314 0m 00s 70
#3richa.tuli11 1m 18s 22
#4y.seong202701 5m 02s -312
#5lsj0803092214 9m 31s -501
#6jeonsaw172333 14m 59s -599
APFIVE © 2020.
Email: [email protected]|Privacy Policy