Java Quiz 4 : Literals, Variables & Type Conversions By Tejas Chaudhari - August 26, 2021 FacebookTwitterPinterestWhatsApp Welcome to your Java Quiz 4 : Literals, Variables & Type Conversions 1. Which of these is long data type literal?a) 0x99fffLb) ABCDEFGc) 0x99fffad) 99671246 2. Which of these can be returned by the operator ?a) Integerb) Booleanc) Characterd) Integer or Boolean 3. Literals in java must be appended by which of these?a) Lb) lc) Dd) L and I 4. Literal can be of which of these data types?a) integerb) floatc) booleand) all of the mentioned 5. Which of these can not be used for a variable name in Java?a) identifierb) keywordc) identifier & keywordd) none of the mentioned 6. What will be the output of the following Java program? class evaluate { public static void main(String args[]) { int a[] = {1,2,3,4,5}; int d[] = a; int sum = 0; for (int j = 0; j < 3; ++j) sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]); System.out.println(sum); } } a) 38b) 39c) 40d) 41 7. What will be the output of the following Java program? 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/2; array_variable[i]++; System.out.print(array_variable[i] + " "); i++; } } } a) 0 2 4 6 8b) 1 2 3 4 5c) 0 1 2 3 4 5 6 7 8 9d) 1 2 3 4 5 6 7 8 9 10 8. What will be the output of the following Java program? class variable_scope { public static void main(String args[]) { int x; x = 5; { int y = 6; System.out.print(x + " " + y); } System.out.println(x + " " + y); } } a) 5 6 5 6b) 5 6 5c) Runtime errord) Compilation error 9. Which of these is an incorrect string literal?a) “Hello World”b) “Hello\nWorld”c) “\”Hello World\””d) "Hello world" 10. What will be the output of the following Java program? class dynamic_initialization { public static void main(String args[]) { double a, b; a = 3.0; b = 4.0; double c = Math.sqrt(a * a + b * b); System.out.println(c); } } a) 5.0b) 25.0c) 7.0d) Compilation Error 11. Which of these is necessary condition for automatic type conversion in Java?a) The destination type is smaller than source typeb) The destination type is larger than source typec) The destination type can be larger or smaller than source typed) None of the mentioned 12. What is the prototype of the default constructor of this Java class? public class prototype { }a) prototype( )b) prototype(void)c) public prototype(void)d) public prototype( ) 13. What will be the error in the following Java code? byte b = 50; b = b * 50;a) b cannot contain value 100, limited by its rangeb) * operator has converted b * 50 into int, which can not be converted to byte without castingc) b cannot contain value 50d) No error in this code 14. If an expression contains double, int, float, long, then the whole expression will be promoted into which of these data types?a) longb) intc) doubled) float 15. What is Truncation is Java?a) Floating-point value assigned to an integer typeb) Integer value assigned to floating typec) Floating-point value assigned to an Floating typed) Integer value assigned to floating type Time is Up!