JAVA Quiz /5 Time is up!! Misc 1 / 5 What will be the output of below code: Copy Code Copied Use a different Browser 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 b. 5 6 5 6 c. Compilation error d. Runtime error Second print statement doesn’t have access to y , scope y was limited to the block defined after initialization of x. 2 / 5 What will be the output of below code: Copy Code Copied Use a different Browser class String_demo { public static void main(String args[]) { char chars[] = {'a', 'b', 'c'}; String s = new String(chars); System.out.println(s); } } a. b b. c c. a d. abc Explanation: String(chars) is a constructor of class string, it initializes string s with the values stored in character array chars, therefore s contains “abc”. 3 / 5 What will be the output of below code: Copy Code Copied Use a different Browser class output { public static void main(String args[]) { String c = "Hello i love java"; boolean var; var = c.startsWith("hello"); System.out.println(var); } } a. False b. 1 c. 0 d. True Explanation: startsWith() method is case sensitive “hello” and “Hello” are treated differently, hence false is stored in var. 4 / 5 What is the valid function to find the length of the string? a. length() b. compare() c. ends() d. toString() The Java String class length() method finds the length of a string. The length of the Java string is the same as the Unicode code units of the string. 5 / 5 What will be the output of below code: Copy Code Copied Use a different Browser class Output { public static void main(String args[]) { int arr[] = {1, 2, 3, 4, 5}; for ( int i = 0; i < arr.length - 2; ++i) System.out.println(arr[i] + " "); } } a. 1 2 3 b. 1 2 c. 1 2 3 4 d. 1 2 3 4 5 Explanation: arr.length() is 5, so the loop is executed for three times. Your score is The average score is 46% 0% Exit