Explain with example how to initialize an array of objects.
Create an array with new key word as follows:
Film films[] = new Film[4];
Use individual element of array films[] with index for creating individual objects of the class. Select the appropriate constructor for sending parameters. The following example depicts this
films[0] = new Film("Shrek",133);
films[1] = new Film("Road to Perdition",117);
films[2] = new Film("The Truth about Cats and Dogs",93);
films[3] = new Film("Enigma",114);
Explain with example how to initialize an array of objects.
An array can be instantiatd in various ways as follows:
int[] arr = new int[5];
int arr[] = new int[5];
int[] arr = Array.newInstance[int, 5];
int[] arr = {0,1,2,3,4};
int[][] arr2 = new int[length1][length2]; //2D array
list1 = new Object[5]; //An array of objects