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. |
Which of the following are legal lines of Java code? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Statements (1), (2), (3), and (4) are correct. (1) is correct because when a floating-point number (a double in this case) is cast to an int, it simply loses the digits after the decimal.(2) and (4) are correct because a long can be cast into a byte. If the long is over 127, it loses its most significant (leftmost) bits.(3) actually works, even though a cast is not necessary, because a long can store a byte. |
2. |
Which of these values can a boolean variable contain? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: Boolean variable can contain only one of two possible values, true and false. |
3. |
Literals in java must be appended by which of these? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Data type long literals are appended by an upper or lowercase L. |
4. |
What is the error in this code? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: While evaluating an expression containing int, bytes or shorts , the whole expression is converted to int then evaluated and result is also of type int. |
5. |
What will this code print? int arr[] = new int [5]; |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: If we trying to print any reference variable internally, toString() will be called which is implemented to return the String in following form: |
6. |
With x = 0, which of the following are legal lines of Java code for changing the value of x to 1? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Operator ++ increases value of variable by 1. x = x + 1 can also be written in shorthand form as x += 1. Also x =+ 1 will set the value of x to 1. |
7. |
On applying Left shift operator, <<, on an integer bits are lost one they are shifted past which position bit? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: The left shift operator shifts all of the bits in a value to the left specified number of times. For each shift left, the high order bit is shifted out and lost, zero is brought in from right. When a left shift is applied to an integer operand, bits are lost once they are shifted past the bit position 31. |
8. |
Which of the following operators can operate on a boolean variable? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Operator Short circuit AND, &&, equal to, == , ternary if-then-else, ?:, are boolean logical operators. += is an arithmetic operator it can operate only on numeric values. |
9. |
What is the value stored in x in following lines of code? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: None. |
10. |
Which of the following loops will execute the body of loop even when condition controlling the loop is initially false? |
|||||||||||||||||||
|