
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: A default no-args constructor is not created because there is a constructor supplied that has an argument, line 4. Therefore the sub-class constructor must explicitly make a call to the super class constructor:
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: Option B is correct. It would be correct if the code had compiled, and the subclass Alpha had been saved in its own file. In this case Java supplies an implicit call from the sub-class constructor to the no-args constructor of the super-class therefore line 12 causes Base to be output. Line 13 also causes Base to be output. Option A is wrong. It would be correct if either the main class or the subclass had not been instantiated. Option C is wrong. The code compiles. Option D is wrong. There is output. Learn more problems on : Declarations and Access Control Discuss about this problem : Discuss in Forum |
3. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: Nonnested classes cannot be marked protected (or final for that matter), so the compiler will fail at protected class NewTreeSet. Learn more problems on : Declarations and Access Control Discuss about this problem : Discuss in Forum |
4. | Which two statements are true for any concrete class implementing the java.lang.Runnable interface?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Explanation: (2) and (6). When a thread's run() method completes, the thread will die. The run() method must be declared public void and not take any arguments. (1) is incorrect because classes can never extend interfaces. (3) is incorrect because the run() method is typically not empty; if it were, the thread would do nothing. (4) is incorrect because the mandatory method is run(). (5) is incorrect because the class implements Runnable. Learn more problems on : Declarations and Access Control Discuss about this problem : Discuss in Forum |
5. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Error is thrown but not recognised line(22) because the only catch attempts to catch an Exception and Exception is not a superclass of Error. Therefore only the code in the finally statement can be run before exiting with a runtime error (Exception in thread "main" java.lang.Error). Learn more problems on : Exceptions 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: (1) A RuntimeException is thrown, this is a subclass of exception. (2) The exception causes the try to complete abruptly (line 7) therefore line 8 is never executed. (3) The exception is caught (line 10) and "B" is output (line 12) (4) The finally block (line 14) is always executed and "C" is output (line 16). (5) The exception was caught, so the program continues with line 18 and outputs "D". Learn more problems on : Exceptions Discuss about this problem : Discuss in Forum |
7. | Which interface does java.util.Hashtable implement? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: Hash table based implementation of the Map interface. Learn more problems on : Objects and Collections Discuss about this problem : Discuss in Forum |
8. | What will be the output of the program?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: Option B is correct. The compiler complains with the error "modifier private not allowed here". The class is created private and is being used by another class on line 19. Learn more problems on : Objects and Collections Discuss about this problem : Discuss in Forum |
9. | What two statements are true about properly overridden hashCode() and equals() methods?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: (3) and (4) are correct. (1) and (2) are incorrect because by contract hashCode() and equals() can't be overridden unless both are overridden. Learn more problems on : Objects and Collections Discuss about this problem : Discuss in Forum |
10. | Which three are methods of the Object class?
|
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: (1), (2), and (6) are correct. They are all related to the list of threads waiting on the specified object. (3), (5), (7), and (8) are incorrect answers. The methods isInterrupted() and interrupt() are instance methods of Thread. The methods sleep() and yield() are static methods of Thread. D is incorrect because synchronized is a keyword and the synchronized() construct is part of the Java language. Learn more problems on : Threads Discuss about this problem : Discuss in Forum |
11. | Which cannot directly cause a thread to stop executing? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Option C is correct. notify() - wakes up a single thread that is waiting on this object's monitor. Learn more problems on : Threads Discuss about this problem : Discuss in Forum |
12. | Which method registers a thread in a thread scheduler? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Option C is correct. The start() method causes this thread to begin execution; the Java Virtual Machine calls the run method of this thread. Option A is wrong. The run() method of a thread is like the main() method to an application. Starting the thread causes the object's run method to be called in that separately executing thread. Option B is wrong. There is no construct() method in the Thread class. Option D is wrong. There is no register() method in the Thread class. Learn more problems on : Threads Discuss about this problem : Discuss in Forum |
13. |
which of these will create and start this thread? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Because the class implements Runnable, an instance of it has to be passed to the Thread constructor, and then the instance of the Thread has to be started. A is incorrect. There is no constructor like this for Runnable because Runnable is an interface, and it is illegal to pass a class or interface name to any constructor. B is incorrect for the same reason; you can't pass a class or interface name to any constructor. D is incorrect because MyRunnable doesn't have a start() method, and the only start() method that can start a thread of execution is the start() in the Thread class. Learn more problems on : Threads Discuss about this problem : Discuss in Forum |
14. |
When is the B object, created in line 3, eligible for garbage collection? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option D Learn more problems on : Garbage Collections Discuss about this problem : Discuss in Forum |
15. |
after line 11 runs, how many objects are eligible for garbage collection? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: This is an example of the islands of isolated objects. By the time line 11 has run, the objects instantiated in lines 6 and 7 are referring to each other, but no live thread can reach either of them. Learn more problems on : Garbage Collections Discuss about this problem : Discuss in Forum |
16. | Which of the following would compile without error? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option A Explanation: The return value of the Math.abs() method is always the same as the type of the parameter passed into that method. In the case of A, an integer is passed in and so the result is also an integer which is fine for assignment to "int a". The values used in B, C & D respectively are a double, a float and a long. The compiler will complain about a possible loss of precision if we try to assign the results to an "int". Learn more problems on : Java.lang Class Discuss about this problem : Discuss in Forum |
17. | What will be the output of the program? How many String objects have been created? |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option C Explanation: Line 1 creates two, one referred to by x and the lost String "xyz". Line 2 creates one (for a total of three). Line 3 creates one more (for a total of four), the concatenated String referred to by x with a value of "xyzabc". Learn more problems on : Java.lang Class Discuss about this problem : Discuss in Forum |
18. | What will be the output of the program? System.out.println(Math.sqrt(-4D)); |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: It is not possible in regular mathematics to get a value for the square-root of a negative number therefore a NaN will be returned because the code is valid. 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: It gives different output while executing the same compiled code at different times. C:\>javac Test.java C:\>java Test ABBCAD C:\>java Test ACADCB C:\>java Test ACBCBAD C:\>java Test ABBCAD C:\>java Test ACBCBAD C:\>java Test ACBCBAD C:\>java Test ABBCAD Learn more problems on : Java.lang Class Discuss about this problem : Discuss in Forum |
20. | Which statement is true given the following? Double d = Math.random(); |
|||||||||||||||||||
Your Answer: Option (Not Answered) Correct Answer: Option B Explanation: The Math.random() method returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0 Learn more problems on : Java.lang Class Discuss about this problem : Discuss in Forum |