Machine-translated by Google. Questions are authored in English.
Top

Threads - General Questions Questions and Answers

Answer: A

ExecutorService, CountDownLatch and TimeUnit all live in java.util.concurrent and need importing. Thread, Runnable, ThreadLocal, Object and InterruptedException are all in java.lang, which is why basic thread code compiles with no import line.

Please log in or register to report this question.

22.

What does Thread.holdsLock(obj) return?

Answer: B

holdsLock is a static method returning a boolean, reporting whether the calling thread holds the monitor of the object passed to it. It is intended for assertions and diagnostics rather than for making decisions in ordinary code.

Please log in or register to report this question.

Answer: C

Correct answer: join(), join(long) and join(long, int)

The three take no timeout, a timeout in milliseconds, and a timeout in milliseconds plus nanoseconds. All are instance methods called on the thread to be waited for, which is why there is no overload taking a Thread argument - the thread is the receiver.

Please log in or register to report this question.

Answer: D

wait is public, final and void, and declares InterruptedException. Being final means no class can override it, which is why the behaviour is identical for every object. It returns nothing, so a caller cannot learn from the return value why it woke.

Please log in or register to report this question.

25.

What type does Thread.MIN_PRIORITY have?

Answer: A

The three priority constants are plain int fields on Thread, declared static and final. There is no priority enum in the API, which is why setPriority takes an int and will reject a value outside the permitted range with IllegalArgumentException.

Please log in or register to report this question.

26.

Which of these calls to setPriority throws IllegalArgumentException?

Answer: B

The permitted range runs from MIN_PRIORITY, which is 1, to MAX_PRIORITY, which is 10, so 11 is rejected with IllegalArgumentException. The other three are all inside the range. The exception is unchecked, so nothing forces a caller to handle it.

Please log in or register to report this question.

Answer: C

Runnable is an interface, so a class implements it rather than extending it, and the implementing method must be public because interface members are. Thread is a class and cannot be implemented. The last option compiles as an unrelated package-private method, not an override.

Please log in or register to report this question.

Answer: B

Executors is a factory class of static methods, and newFixedThreadPool is the one that takes a thread count. ExecutorService is an interface and cannot be constructed, and there is no public FixedThreadPool class to instantiate.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Threads - General Questions Questions and Answers || Threads - General Questions MCQ Questions and Answers || Threads - General Questions GK Questions and Answers || Threads - General Questions GK MCQ Questions || Threads - General Questions Multiple Choice Questions and Answers || Threads - General Questions GK || GK on Threads - General Questions || Java Programming Questions and Answers || Java Programming MCQ Questions and Answers || Java Programming GK Questions and Answers || GK on Java Programming