|
No. |
Java Question |
Answer/Output |
Explanation |
|
1 |
int sampleArray[] = null; |
No Error |
|
|
2 |
int[] sampleArray = new int[5];
sampleArray.length = 7; |
Compile Time Error |
Once an array is created then it is not possible to change the length of the array. |
|
3 |
char[] c = new char[200];
SOP(c[78]); |
'\u0000'; |
- |
|
4 |
int a[] = new int[4];
int b=0;
a[a[b]] = a[b] = b = 2;
SOP(a[0]); |
2 |
- |
|
5 |
byte b = 8;
int [] arr = new int[s];
s = 15;
SOP(arr.length); |
8 |
- |
|
6 |
int arr[] = new int[3];
SOP(arr); |
F@107077e |
- |
|
7 |
String str[] = new String[3];
SOP(str); |
[Ljava.lang.String;@107077e |
- |
|
8 |
String str[][] = new String [3][];
SOP(arr); |
[Ljava.lang.String;@107077e |
- |
|
9 |
int a[] = new int[0]; |
No Errors |
- |
|
10 |
int arr[] =new int[0];
SOP(arr[0]); |
No compile time error but throws exception at runtime. (ArraysIndexOutOfBoundsException) |
- |
|
11 |
int [] i = new int[-2]; |
Generates NegativeArraySizeException |
- |
|
12 |
SOP(null); |
Compile Time Error because reference to println is ambiguous. |
- |
|
13 |
SOP((String)null); |
null |
- |
|
14 |
SOP((char [])null); |
No compile time error but generates NullPointerException. |
- |
|
15 |
byte [] b1 = null;
byte [] b2 = null;
SOP(b1+b2); |
Compile Time Error |
+ cannot be applied to byte[] |
|
16 |
byte [] b1 = null;
byte [] b2 = null;
SOP(""+b1+b2); |
nullnull |
- |