What is the output of the following code?
public class Main { public static void main(String args[]) { int[] arr = new int[5]; byte b = 4; char c = 'c'; long longVar = 10; arr[0] = b; /*from w w w . j ava2s.c o m*/ arr[1] = c; arr[3] = longVar; System.out.println(arr[0] + arr[1] + arr[2] + arr[3]); } }
e
The code in this question won't compile due to
arr[3] = longVar;
The preceding line of code tries to assign a value of type long to a variable of type int.
Because Java doesn't support implicit narrowing conversions (for example, long to int in this case), the assignment fails.