Instruction
- Total number of questions : 20.
- Time alloted : 20 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? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: None. |
11. |
Which of the following is a valid declaration of an object of class Box? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: None. |
12. |
Which of the following is a method having same name as that of it’s class? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: A constructor is a method that initializes an object immediately upon creation. It has the same name as that of class in which it resides. |
13. |
Which of the following is a method having same name as that of its class? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: A constructor is a method that initializes an object immediately upon creation. It has the same name as that of class in which it resides. |
14. |
Which of these is correct about passing an argument by call-by-value process? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: When we pass an argument by call-by-value a copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have no effect on original argument, they remain the same. |
15. |
Which of these is used as default for a member of a class if no access specifier is used for it? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: When we pass an argument by call-by-value a copy of argument is made into the formal parameter of the subroutine and changes made on parameters of subroutine have no effect on original argument, they remain the same. |
16. |
Which of these cannot be declared static? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: static statements are run as soon as class containing then is loaded, prior to any object declaration. |
17. |
Which of these keywords is used to refer to member of base class from a sub class? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super. |
18. |
A class member declared protected becomes member of subclass of which type? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: A class member declared protected becomes private member of subclass. |
19. |
Which of these keywords can be used to prevent Method overriding? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: To disallow a method from being overridden, specify final as a modifier at the start of its declaration. Methods declared as final cannot be overridden. |
20. |
Which of these method of Object class is used to obtain class of an object at run time? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: None. |