Instruction
- Total number of questions : 10.
- Time alloted : 10 minutes.
- Each question carry 1 mark.
- No Negative marks
- DO NOT refresh the page.
- All the best :-).
1. |
What is the output of this program? class average { public static void main(String args[]) { double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5}; double result; result = 0; for (int i = 0; i < 6; ++i) result = result + num[i]; System.out.print(result/6);
} } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: None. |
2. |
What is the output of this program? class mainclass { public static void main(String args[]) { char a = 'A'; a++; System.out.print((int)a); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: ASCII value of ‘A’ is 65, on using ++ operator character value increments by one. |
3. |
What is the output of this 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++; } } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: When an array is declared using new operator then all of its elements are initialized to 0 automatically. for loop body is executed 5 times as whenever controls comes in the loop i value is incremented twice, first by i++ in body of loop then by ++i in increment condition of for loop. |
4. |
What is the output of this program? 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); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: Type casting a larger variable into a smaller variable results in modulo of larger variable by range of smaller variable. b contains 300 which is larger than byte’s range i:e -128 to 127 hence d contains 300 modulo 256 i:e 44. |
5. |
What is the output of this program? 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); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: arr[][] is a 2D array, array has been allotted memory in parts. 1st row contains 1 element, 2nd row contains 2 elements and 3rd row contains 3 elements. each element of array is given i + j value in loop. sum contains addition of all the elements of the array. |
6. |
What is the output of this program? class Modulus { public static void main(String args[]) { double a = 25.64; int b = 25; a = a % 10; b = b % 10; System.out.println(a + " " + b); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: Modulus operator returns the remainder of a division operation on the operand. a = a % 10 returns 25.64 % 10 i:e 5.640000000000001. Similarly b = b % 10 returns 5. |
7. |
What is the output of this program? class bitwise_operator { public static void main(String args[]) { int a = 3; int b = 6; int c = a | b; int d = a & b; System.out.println(c + " " + d); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: And operator produces 1 bit if both operand are 1. Or operator produces 1 bit if any bit of the two operands in 1. |
8. |
What is the output of this program? class bool_operator { public static void main(String args[]) { boolean a = true; boolean b = !true; boolean c = a | b; boolean d = a & b; boolean e = d ? b : c; System.out.println(d + " " + e); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Operator | returns true if any one operand is true, thus ‘c = true | false’ is true. Operator & returns a true if both of the operand is true thus d is false. Ternary operator ?: assigns left of ‘:’ if condition is true and right hand of ‘:’ if condition is false. d is false thus e = d ? b : c , assigns c to e , e contains true. |
9. |
What is the output of this program? class operators { public static void main(String args[]) { int x = 8; System.out.println(++x * 3 + " " + x); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Operator ++ has higher precedence than multiplication operator, *, x is incremented to 9 than multiplied with 3 giving 27. |