Why create arraylist outside default constructor but then assign it in the construtor? What does this do? Couldnt you create it all within the constructor or outside of it?
Here is a piece example i saw:
public class Tickets {
public ArrayList <movie> movies;
public Tickets() {
movies = new ArrayList <movie>(); //assigning movie to array list
}
>Solution :
The line:
public ArrayList <movie> movies;
… does not create an ArrayList object. That line defines a variable that will hold, but does not yet hold, a reference to an ArrayList object. Holding no reference means the value of this variable is null.
That line created a receptacle, but did not fill it.
Your new ArrayList <movie>() code creates an ArrayList object. That object lives in memory. That code returns a reference to that new object (effectively its address in memory).
Your movies = code captures that returned reference (the quasi memory location) and stores it in your variable, for later use in your other code.
By the way, your movie class should be spelled Movie.