Static Variable in a Constructor
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
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | kaisuki | 1 | 2 | 0m 00s | 90 |
| #2 | sailajavadlamani33 | 1 | 4 | 0m 00s | 70 |
| #3 | richa.tuli | 1 | 1 | 1m 18s | 22 |
| #4 | raufyildirim95 | 0 | 1 | 2m 37s | -167 |
| #5 | liuwilliam072410 | 1 | 4 | 4m 43s | -213 |
| #6 | zgj07310417 | 1 | 2 | 6m 02s | -272 |
| #7 | y.seong2027 | 0 | 1 | 5m 02s | -312 |
| #8 | lsj08030922 | 1 | 4 | 9m 31s | -501 |
| #9 | chunxiangxu.cxu | 1 | 2 | 9m 54s | -504 |
| #10 | jeonsaw1723 | 3 | 3 | 14m 59s | -599 |
Items per page:
10
1 – 10 of 10
APFIVE