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 increment { public static void main(String args[]) { int g = 3; System.out.print(++g * 8); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32. |
2. |
What is the output of this program? class booloperators { public static void main(String args[]) { boolean var1 = true; boolean var2 = false; System.out.println((var2 & var2)); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: boolean ‘&’ operator always returns true or false. var1 is defined true and var2 is defined false hence their ‘&’ operator result is false. |
3. |
Which of these is incorrect string literal? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: all string literals must begin and end in same line. |
4. |
What is the output of this 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]); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: In argument[0] = args;, the reference variable arg[0], which was referring to an array with two elements, is reassigned to an array (args) with three elements. |
5. |
What is the output of this program? 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] + ""); } } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: None. |
6. |
Can 8 byte long data type be automatically type cast to 4 byte float data type? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: Both data types have different memory representation that’s why 8-byte integral data type can be stored to 4-byte floating point data type. |
7. |
What is the output of this program? class rightshift_operator { public static void main(String args[]) { int x; x = 10; x = x >> 1; System.out.println(x); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: Right shift operator, >>, devides the value by 2. |
8. |
What is the output of this program? class Output { public static void main(String args[]) { int x , y = 1; x = 10; if (x != 10 && x / 0 == 0) System.out.println(y); else System.out.println(++y); } } |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: Operator short circuit and, &&, skips evaluating right hand operand if left hand operand is false thus division by zero in if condition does not give an error. |
9. |
Which of these lines of code will give better performance? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Parentheses do not degrade the performance of the program. Adding parentheses to reduce ambiguity does not negatively affect your system. |
10. |
What is the output of this program? class Output { public static void main(String args[]) { final int a=10,b=20; while(a<b) { System.out.println("Hello"); } System.out.println("World"); } } |
|||||||||||||||||||
|