Saturday, September 10, 2011

1. What are Limitations of Object Arrays and define arrays?

- An Array is a indexed collection of fixed number of homogenous data types. 

- The main limitation of array is fixed in size i.e, once the array is created then there is no chance for   increasing/decreasing of the array as per our requirement

Different types of Arrays:
1. Single Dimensional  Arrays
 Syntax:
int[] a ; //Recommended to use, because name is clearly separated from the type
int a[];
int []a;

We are no allowed to specify the array size during declaration, Compile time error
i.e., int[6] a; // compile time error


2. Two Dimensional Arrays
Syntax:
int[][] a;
int a[][];
int[] a[];
int [][]a;
int[] []a;
int []a[]; // All these are possible array declarations

3. Three Dimensional Arrays
ll'y for the three dimensional arrays declarations

Few more things:

- int[] a=new int[6]; //valid declaration
- int[6] a=new int[]; // invalid declaration compile time error
- int[] a =new int[0]; // valid declaration but cannot store elements
- int[] a = new int[null]; // invalid declaration - CE: in compatible types
- int[] a = new int[-6]; // invalid Declaration - RE: Negative Array Size Exception
- When ever single dimensional array is present , we can replace it var-arg parameter. and viceversa is not possible




No comments:

Post a Comment

Note: Only a member of this blog may post a comment.