#126 – Initializing Arrays of Reference-Type Objects

You can also use an array initialization expression to initialize an array of objects that belong to a reference type.

For example, if you have a Book class with a constructor that takes three arguments, you can initialize an array of books this way:

 Book[] books = { new Book("Moby Dick", "Melville", "Herman"),
                  new Book("Ulysses", "Joyce", "James"),
                  new Book("The Great Gatsby", "Fitzgerald", "F. Scott")};
Advertisements