Static Variable in a Constructor
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
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 | y.seong2027 | 0 | 1 | 5m 02s | -312 |
| #5 | lsj08030922 | 1 | 4 | 9m 31s | -501 |
| #6 | jeonsaw1723 | 3 | 3 | 14m 59s | -599 |
APFIVE