Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
medium Solved by 13 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

5

B

0

C

2

D

7

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

Question Leaderboard

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

AI Tutor

How can I help?

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