Why is the default constructor used in this method?
public static TicketCounterSingle getInstance() {
if (instance == null) {
instance = new TicketCounterSingle();
}
return instance;
}
This is the full class:
public class TicketCounterSingle {
private static TicketCounterSingle instance;
String Name;
int avail;
private TicketCounterSingle(String Name, int avail) {
this.avail = avail;
this.Name = Name;
}
public String getName() {
return Name;
}
public synchronized boolean bookTicket(int ticket) {
if (avail >= ticket) {
avail = avail - ticket;
return true;
} else {
return false;
}
}
public static TicketCounterSingle getInstance() {
if (instance == null) {
instance = new TicketCounterSingle();
}
return instance;
}
}