public class Counter {
private int count;
public Counter() { count = 0; }
public void inc() { count++; }
public int getCount() { return count; }
}
// ...
Counter c = new Counter();
c.inc(); c.inc(); c.inc();
System.out.println(c.getCount());What is printed?
- Acheck_circle
3
- B
0
- C
1
- D
Compile-time error
Explanation
The default constructor sets count to 0; inc() is called three times, so count becomes 3.