4.9. Sample exam questions
What is the output of the following code?
class EJavaGuruArray { public static void main(String args[]) { int[] arr = new int[5]; byte b = 4; char c = 'c'; long longVar = 10; arr[0] = b; arr[1] = c; arr[3] = longVar; System.out.println(arr[0] + arr[1] + arr[2] + arr[3]); } }
- 4c010
- 4c10
- 113
- 103
- Compilation error
What is the output of the following code?
class EJavaGuruArray2 { public static void main(String args[]) { int[] arr1; int[] arr2 = new int[3]; char[] arr3 = {'a', 'b'}; arr1 = arr2; arr1 = arr3; System.out.println(arr1[0] + ":" + arr1[1]); } }
- 0:0
- a:b
- 0:b
- a:0
- Compilation error
Which of the following are valid lines of code to define a multidimensional int array?
- int[][] array1 ...
Get OCA Java SE 8 Programmer I Certification Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.