I'm used to C++, where you have to instantiate everything in the constructer, but a recent realization has made me very confused about java. I was just instantiating things in the constructer, and then I realized this syntax was valid:
public class DebateCompetition {
private boolean isAdvanced;
ArrayList<Debate> debates = new ArrayList<Debate>(); //<------
ArrayList<Team> teams;
ArrayList<School> schools;
public void addSchool(School s) {
schools.add(s);
}
}
But that leaves a lot of questions. First: What does it do? Second: When is new ArrayList<Debate>()
called? Third: Is this a best practice, or not?