#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

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: