Can we specify array size with long data type value?
class Array5
{
public static void main(String[] args)
{
int[] x=new int[10L];
System.out.println(x);
}
}
/*
Output:- CE[possible loss of precision]
Explanation:- To specify array size the allowed data types are (char,byte,short,int).
By mistake if we are trying to provide any other type then we will get compilation error.
These are valid array creation :-
int[] x=new int['a'];
byte b=10;
int[] x=new int[b];
short s=12;
int[] x=new int[s];
int[] x=new int[14];
*/
{
public static void main(String[] args)
{
int[] x=new int[10L];
System.out.println(x);
}
}
/*
Output:- CE[possible loss of precision]
Explanation:- To specify array size the allowed data types are (char,byte,short,int).
By mistake if we are trying to provide any other type then we will get compilation error.
These are valid array creation :-
int[] x=new int['a'];
byte b=10;
int[] x=new int[b];
short s=12;
int[] x=new int[s];
int[] x=new int[14];
*/
0 comments: