Explain how to initialize an array of objects


How to initialize an array of objects

<<Previous   Next>>

Java - how to initialize an array of objects - Feb 28, 2010 at 16:16 PM by Vidya Sagar

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);

Java - how to initialize an array of objects - 19 Jan, 2009 at 15:00 PM by Amit Satpute 

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 

<<Previous   Next>>
Explain the difference between static and non-static member of a class.

A static field belongs to a class. The objects of the class can not have the copy of these fields. These fields are referred by the class name. Ex: Employee. company. Without creating an instance of a class, these fields can be accessed...................

What is the difference between the File and RandomAccessFile classes?

The File class is used to perform the operations on files and directories of the file system of an operating system. This operating system is the platform for the java application that uses the File class objects............... 

Write your comment - Share Knowledge and Experience


Interview questions
Latest MCQs
» General awareness - Banking » ASP.NET » PL/SQL » Mechanical Engineering
» IAS Prelims GS » Java » Programming Language » Electrical Engineering
» English » C++ » Software Engineering » Electronic Engineering
» Quantitative Aptitude » Oracle » English » Finance
Home | About us | Sitemap | Contact us