Our lecturer showed us this code yesterday. And I didn't understand why he wrote extra access modifiers. When I delete some parts of code, it is still running.
public class Counter {
private final String name;
private int count;
public Counter(String id) {
name = id;
count = 0;
}
public void increment() {
count += 1;
}
public int tally() {
return count;
}
public String toString() {
return count + " " + name;
}
public static void main(String[] args) {
Counter c0 = new Counter("first");
Counter c1 = new Counter("second");
c0.increment();
c0.increment();
c1.increment();
System.out.println("c0 counter is " + c0);
System.out.println("c1 counter is " + c1);
}
then I delete access modifiers and;
public static void main(String[] args) {
Counter c0 = new Counter("first");
Counter c1 = new Counter("second");
c0.increment();
c0.increment();
c1.increment();
System.out.println("c0 counter is " + c0);
System.out.println("c1 counter is " + c1);
}
the code is still running. Actually I'm not very good at this so can someone tell basically?