|
Directions to Solve
In questions below, each passage consist of six sentences. The first and sixth sentence are given in the begining. The middle four sentences in each have been removed and jumbled up. These are labelled as P, Q, R and S. Find out the proper order for the four sentences.
ANS:B -
QPSR
No answer description is available.
|
A It prints garbage values infinitely
B No Error and print nothing
C Runs infinitely without printing anything
D Error: main() cannot be called inside printf()
ANS:B - Runs infinitely without printing anything
In printf("%p\n", main()); it calls the main() function and then it repeats infinetly, untill stack overflow.
|
ANS:C - 3 and 4
(3) and (4) are correct.
(1) and (2) are incorrect because by contract hashCode() and equals() can't be overridden unless both are overridden.
|
ANS:A - 1 and 4
(1) is a restatement of the equals() and hashCode() contract. (4) is true because if the hashCode() comparison returns ==, the two objects might or might not be equal.
(2) and (3) are incorrect because the hashCode() method is very flexible in its return values, and often two dissimilar objects can return the same hash code value.
|
B x5.hashCode() != x6.hashCode()
D x3.hashCode() == x4.hashCode()
ANS:A - x2.equals(x1)
By contract, if two objects are equivalent according to the equals() method, then the hashCode() method must evaluate them to be ==.
Option A is incorrect because if the hashCode() values are not equal, the two objects must not be equal.
Option C is incorrect because if equals() is not true there is no guarantee of any result from hashCode().
Option D is incorrect because hashCode() will often return == even if the two objects do not evaluate to equals() being true.
|
ANS:B - 1, 3, 4 and 5
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.
|
A The collection is guaranteed to be immutable.
B The elements in the collection are guaranteed to be unique.
C The elements in the collection are accessed using a unique key.
D The elements in the collection are ordered.
ANS:A - The elements in the collection are ordered.
Yes, always the elements in the collection are ordered.
|
ANS:B - start();
Option B 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. There is no init() method in the Thread class.
Option C 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 D is wrong. The resume() method is deprecated. It resumes a suspended thread.
|
ANS:C - 1 and 2
(1) and (2) are both valid constructors for Thread.
(3), (4), and (5) are not legal Thread constructors, although (4) is close. If you reverse the arguments in (4), you'd have a valid constructor.
|
ANS:C - 1, 2, 6
(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
|