Values and Data types II Values and Data types II Arrays and Data Types, Data Type Limits and Overflow, String Immutability, Type Conversion with Expressions, Arrays and Default Values, Floating-Point Precision, Variable Initialization 1 / 10 What will the following code produce? int[] arr = new int[5]; System.out.println(arr[2]); 0 Compilation Error Runtime Error Undefined Value Elements of an int array are initialized to 0 by default. Elements of an int array are initialized to 0 by default. 2 / 10 Which of the following is true about arrays in Java? Arrays can store elements of different data types. The size of an array can be changed after initialization. Multidimensional arrays are stored as arrays of arrays. Arrays are immutable. 3 / 10 What is the result of this code? float f = 3.4f; double d = f; System.out.println(d); 3.4 3.4000000953674316 Compilation Error Runtime Error Floating-point precision can vary when converting from float to double Floating-point precision can vary when converting from float to double 4 / 10 What will the following code print? boolean b = true; System.out.println(b ? “Yes” : “No”); Yes No Compilation Error Runtime Error The ternary operator evaluates the condition and returns the first value if true The ternary operator evaluates the condition and returns the first value if true 5 / 10 What will the following code output? int a = Integer.MAX_VALUE; int b = a + 1; System.out.println(b); 2147483647 -2147483648 Compilation Error Runtime Error Adding 1 to Integer.MAX_VALUE causes overflow, wrapping to Integer.MIN_VALUE Adding 1 to Integer.MAX_VALUE causes overflow, wrapping to Integer.MIN_VALUE 6 / 10 What happens when the following code is executed? String s = “Hello”; s.concat(” World”); System.out.println(s); Hello World Hello Compilation Error Runtime Error Strings are immutable. concat creates a new string, but the original s remains unchanged. Strings are immutable. concat creates a new string, but the original s remains unchanged. 7 / 10 What will the following code print? byte a = 40; byte b = 50; byte c = (byte) (a * b); System.out.println(c); 2000 Overflow -48 Compilation Error a * b results in an int (default for arithmetic). Casting back to byte causes overflow.) a * b results in an int (default for arithmetic). Casting back to byte causes overflow.) 8 / 10 Consider the following array declaration. What will be the output of the code? boolean[] arr = new boolean[3]; System.out.println(arr[1]); true false Compilation Error Runtime Error The default value for elements in a boolean array is false The default value for elements in a boolean array is false 9 / 10 What will the following code output? double d = 0.1 + 0.2; System.out.println(d == 0.3); true false Compilation Error Runtime Error Due to precision issues with floating-point arithmetic, 0.1 + 0.2 does not exactly equal 0.3. Due to precision issues with floating-point arithmetic, 0.1 + 0.2 does not exactly equal 0.3. 10 / 10 What happens when the following code is executed? int x; System.out.println(x); It prints the default value 0. It throws a NullPointerException. It results in a compilation error. It throws an uninitialized variable error at runtime. Local variables must be initialized before they are accessed in Java Local variables must be initialized before they are accessed in Java Your score is By WordPress Quiz plugin