
Instruction:
- This is a FREE online test. DO NOT pay money to anyone to attend this test.
- Total number of questions : 20.
- Time alloted : 30 minutes.
- Each question carry 1 mark, no negative marks.
- DO NOT refresh the page.
- All the best :-).
1. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Compilation failed because static was an illegal start of expression - method variables do not have a modifier (they are always considered local). Learn more problems on : Declarations and Access Control Discuss about this problem : Discuss in Forum |
2. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: Output: 15 15 The reference variables a1 and a3 refer to the same long array object. When the [1] element is updated in the fix() method, it is updating the array referred to by a1. The reference variable a2 refers to the same array object. So Output: 3+7+5+" "3+7+5 Output: 15 15 Because Numeric values will be added Learn more problems on : Operators and Assignments Discuss about this problem : Discuss in Forum |
3. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: The code will not compile because in line 7, the line will work only if we use (x==y) in the line. The == operator compares values to produce a boolean, whereas the = operator assigns a value to variables. Option A, B, and D are incorrect because the code does not get as far as compiling. If we corrected this code, the output would be false. Learn more problems on : Operators and Assignments Discuss about this problem : Discuss in Forum |
4. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: The & operator produces a 1 bit when both bits are 1. The result of the & operation is 9. The ^ operator produces a 1 bit when exactly one bit is 1; the result of this operation is 10. The | operator produces a 1 bit when at least one bit is 1; the result of this operation is 14. Learn more problems on : Operators and Assignments Discuss about this problem : Discuss in Forum |
5. | What will be the output of the program?
|
||||||||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: The & operator has a higher precedence than the | operator so that on line 8 b1 and b2 are evaluated together as are b2 & b3. The final b1 in line 10 is what causes that if test to be true. Hence it prints "dokey". Learn more problems on : Operators and Assignments Discuss about this problem : Discuss in Forum |
6. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Compilation fails because the while loop demands a boolean argument for it's looping condition, but in the code, it's given an int argument. while(true) { //insert code here } Learn more problems on : Flow Control Discuss about this problem : Discuss in Forum |
7. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Compilation fails on the line 5 - System.out.println(i); as the variable i has only been declared within the for loop. It is not a recognised variable outside the code block of loop. Learn more problems on : Flow Control Discuss about this problem : Discuss in Forum |
8. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Line 3 uses an assignment as opposed to comparison. Because of this, the if statement receives an integer value instead of a boolean. And so the compilation fails. Learn more problems on : Flow Control Discuss about this problem : Discuss in Forum |
9. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: A Run time exception is thrown and caught in the catch statement on line 10. All the code after the finally statement is run because the exception has been caught. Learn more problems on : Exceptions Discuss about this problem : Discuss in Forum |
10. |
At Point X on line 5, which code is necessary to make the code compile? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: Option B is correct. This works because it DOES throw an exception if an error occurs. Option A is wrong. If you compile the code as given the compiler will complain: "unreported exception must be caught or declared to be thrown" The class extends Exception so we are forced to test for exceptions. Option C is wrong. The catch statement belongs in a method body not a method specification. Option D is wrong. TestException is a subclass of Exception therefore the test method, in this example, must throw TestException or some other class further up the Exception tree. Throwing RuntimeException is just not on as this belongs in the java.lang.RuntimeException branch (it is not a superclass of TestException). The compiler complains with the same error as in A above. Learn more problems on : Exceptions Discuss about this problem : Discuss in Forum |
11. | You need to store elements in a collection that guarantees that no duplicates are stored. Which one of the following interfaces provide that capability? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: Option A is correct. A Map cannot contain duplicate keys. Option B is wrong. Lists typically allow duplicate elements. Option C is wrong. Collection allows duplicate elements. Learn more problems on : Objects and Collections Discuss about this problem : Discuss in Forum |
12. | Which collection class allows you to access its elements by associating a key with an element's value, and provides synchronization? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Hashtable is the only class listed that provides synchronized methods. If you need synchronization great; otherwise, use HashMap, it's faster. Learn more problems on : Objects and Collections Discuss about this problem : Discuss in Forum |
13. | What is the numerical range of char? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: The char type is integral but unsigned. The range of a variable of type char is from 0 to 216-1 or 0 to 65535. Java characters are Unicode, which is a 16-bit encoding capable of representing a wide range of international characters. If the most significant nine bits of a char are 0, then the encoding is the same as seven-bit ASCII. Learn more problems on : Objects and Collections Discuss about this problem : Discuss in Forum |
14. | Which of the following are true statements?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: The ListIterator interface extends the Iterator interface and declares additional methods to provide forward and backward iteration capabilities, List modification capabilities, and the ability to determine the position of the iterator in the List. Learn more problems on : Objects and Collections Discuss about this problem : Discuss in Forum |
15. | Which method must be defined by a class implementing the java.lang.Runnable interface? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: Option B is correct because in an interface all methods are abstract by default therefore they must be overridden by the implementing class. The Runnable interface only contains 1 method, the void run() method therefore it must be implemented. Option A and D are incorrect because they are narrowing the access privileges i.e. package(default) access is narrower than public access. Option C is not method in the Runnable interface therefore it is incorrect. Learn more problems on : Threads Discuss about this problem : Discuss in Forum |
16. | Which two statements are true?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Statements (4) and (6) are correct. (4) is correct because the wait() method is overloaded to accept a wait duration in milliseconds. If the thread has not been notified by the time the wait duration has elapsed, then the thread will move back to runnable even without having been notified. (6) is correct because wait()/notify()/notifyAll() must all be called from within a synchronized, context. A thread must own the lock on the object its invoking wait()/notify()/notifyAll() on. (1) is incorrect because wait()/notify() will not prevent deadlock. (2) is incorrect because a sleeping thread will return to runnable when it wakes up, but it might not necessarily resume execution right away. To resume executing, the newly awakened thread must still be moved from runnable to running by the scheduler. (3) is incorrect because synchronization prevents two or more threads from accessing the same object. (5) is incorrect because notify() is not overloaded to accept a duration. Learn more problems on : Threads Discuss about this problem : Discuss in Forum |
17. | Which of the following statements is true? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Option C is true because multiple VM flags can be used on a single invocation of a Java program. Option A is incorrect because at runtime assertions are ignored by default. Option B is incorrect because as of Java 1.4 you must add the argument -source 1.4 to the command line if you want the compiler to compile assertion statements. Option D is incorrect because the VM evaluates all assertion flags left to right. Learn more problems on : Assertions Discuss about this problem : Discuss in Forum |
18. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: The xxxValue() methods convert any numeric wrapper object's value to any primitive type. When narrowing is necessary, significant bits are dropped and the results are difficult to calculate. Learn more problems on : Java.lang Class Discuss about this problem : Discuss in Forum |
19. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Initially this looks like a question about the logical and logical shortcut operators "|" and "||" but on closer inspection it should be noticed that the name of the boolean method in this code is "catch". "catch" is a reserved keyword in the Java language and cannot be used as a method name. Hence Compilation will fail. Learn more problems on : Java.lang Class Discuss about this problem : Discuss in Forum |
20. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Learn more problems on : Java.lang Class Discuss about this problem : Discuss in Forum |