Java Quiz 5 : Promotions & Casting, Arrays By Tejas Chaudhari - August 27, 2021 FacebookTwitterPinterestWhatsApp Welcome to your Java Quiz 5 : Promotions & Casting, Arrays 1. What will be the output of the following Java code? class char_increment { public static void main(String args[]) { char c1 = 'D'; char c2 = 84; c2++; c1++; System.out.println(c1 + " " + c2); } } a) E Ub) U Ec) V Ed) U F 2. What will be the output of the following Java code? class conversion { public static void main(String args[]) { double a = 295.04; int b = 300; byte c = (byte) a; byte d = (byte) b; System.out.println(c + " " + d); } } a) 38 43b) 39 44c) 295 300d) 295.04 300 3. What will be the output of the following Java code? What will be the output of the following Java code? class A { final public int calculate(int a, int b) { return 1; } } class B extends A { public int calculate(int a, int b) { return 2; } } public class output { public static void main(String args[]) { B object = new B(); System.out.print("b is " + b.calculate(0, 1)); } } a) b is : 2b) b is : 1c) Compilation Errord) An exception is thrown at runtime 4. What will be the output of the following Java program, if we run as “java main_arguments 1 2 3”? class main_arguments { public static void main(String [] args) { String [][] argument = new String[2][2]; int x; argument[0] = args; x = argument[0].length; for (int y = 0; y < x; y++) System.out.print(" " + argument[0][y]); } } a) 1 1b) 1 0c) 1 0 3d) 1 2 3 5. What will be the output of the following Java program? class c { public void main( String[] args ) { System.out.println( "Hello" + args[0] ); } } a) Hello cb) Helloc) Hello worldd) Runtime Error 6. Which of these operators is used to allocate memory to array variable in Java?a) mallocb) allocc) newd) new malloc 7. Which of these is an incorrect array declaration?a) int arr[] = new int[5]b) int [] arr = new int[5]c) int arr[] = new int[5]d) int arr[] = int [5] new 8. What will be the output of the following Java code? int arr[] = new int [5]; System.out.print(arr);a) 0b) value stored in arr[0]c) 00000d) Class [email protected] hashcode in hexadecimal form 9. Which of these is an incorrect Statement?a) It is necessary to use new operator to initialize an arrayb) Array can be initialized using comma separated expressions surrounded by curly bracesc) Array can be initialized when they are declaredd) None of the mentioned 10. Which of these is necessary to specify at time of array initialization?a) Rowb) Columnc) Both Row and Columnd) None of the mentioned 11. What will be the output of the following Java code? class array_output { public static void main(String args[]) { int array_variable [] = new int[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = i; System.out.print(array_variable[i] + " "); i++; } } } a) 0 2 4 6 8b) 1 3 5 7 9c) 0 1 2 3 4 5 6 7 8 9d) 1 2 3 4 5 6 7 8 9 10 12. What will be the output of the following Java code? class multidimention_array { public static void main(String args[]) { int arr[][] = new int[3][]; arr[0] = new int[1]; arr[1] = new int[2]; arr[2] = new int[3]; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) arr[i][j] = j + 1; for (int i = 0; i < 3; ++i) for (int j = 0; j < i + 1; ++j) sum + = arr[i][j]; System.out.print(sum); } } a) 11b) 10c) 13d) 14 13. What will be the output of the following Java code? class evaluate { public static void main(String args[]) { int arr[] = new int[] {0 , 1, 2, 3, 4, 5, 6, 7, 8, 9}; int n = 6; n = arr[arr[n] / 2]; System.out.println(arr[n] / 2); } } a) 3b) 0c) 6d) 1 14. What will be the output of the following Java code? class array_output { public static void main(String args[]) { char array_variable [] = new char[10]; for (int i = 0; i < 10; ++i) { array_variable[i] = 'i'; System.out.print(array_variable[i] + ""); } } } a) 1 2 3 4 5 6 7 8 9 10b) 0 1 2 3 4 5 6 7 8 9 10c) i j k l m n o p q rd) i i i i i i i i i i 15. What will be the output of the following Java code? class array_output { public static void main(String args[]) { int array_variable[][] = {{ 1, 2, 3}, { 4 , 5, 6}, { 7, 8, 9}}; int sum = 0; for (int i = 0; i < 3; ++i) for (int j = 0; j < 3 ; ++j) sum = sum + array_variable[i][j]; System.out.print(sum / 5); } } a) 8b) 9c) 10d) 11 Time is Up!