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

Threads - General Questions Questions and Answers

Answer: A

Modifiers may appear in any order before the return type, so static synchronized and synchronized static are equally valid, but the keyword cannot follow the return type and a method with a body needs braces. abstract and synchronized cannot be combined.

Please log in or register to report this question.

Answer: B

Collections provides static wrapper methods that return a synchronized view of an existing collection. There is no SynchronizedList class to instantiate, no synchronized method on a collection, and the keyword cannot be applied to a variable.

Please log in or register to report this question.

Answer: C

Correct answer: BlockingQueue<Job> q = new LinkedBlockingQueue<Job>();

BlockingQueue is an interface, so it cannot be instantiated; LinkedBlockingQueue and ArrayBlockingQueue are the usual implementations. A LinkedList would compile as a plain Queue but would return null on an empty queue rather than blocking.

Please log in or register to report this question.

Answer: D

Correct answer: void uncaughtException(Thread t, Throwable e)

The handler receives both the thread that died and the throwable that killed it, and it returns nothing - there is nothing useful it could return, the thread being already finished. It catches Throwable rather than Exception, so errors are covered too.

Please log in or register to report this question.

Answer: A

Callable is generic, and the type argument fixes what call returns. Runnable is not generic and its run returns void, a raw Callable would make call return Object, and Callable is an interface so a class implements it.

Please log in or register to report this question.

66.

Which of these correctly reports how many threads are active in the current thread group?

Answer: B

activeCount is a static method on Thread returning an int estimate for the current thread's group and its subgroups. It is documented as an estimate intended for diagnostics, because threads may start or finish while it is counting.

Please log in or register to report this question.

67.

Which of these declarations of a task field is thread-safe to publish without further synchronization?

Answer: C

A final field assigned in the constructor is guaranteed visible to any thread that sees the fully constructed object, which is the freeze guarantee the language gives final. A plain or static field offers no such promise, and transient concerns serialization rather than threading.

Please log in or register to report this question.

68.

Which of these is the correct order of arguments to Thread(ThreadGroup, Runnable, String)?

Answer: D

The constructor takes the group first, then the Runnable, then the name. Every Thread constructor that accepts a group puts it first, and the name always comes last where present, so the shorter forms are consistent prefixes of the longest.

Please log in or register to report this question.

Answer: A

Correct answer: class Job extends Thread { public void run() { } }

An override cannot narrow the visibility of the method it overrides, so a package-private run() will not compile against the public one in Thread. Nor can the return type be changed to int, and Java permits only one superclass, so the comma-separated extends is not legal syntax.

Please log in or register to report this question.

Answer: B

Correct answer: Condition c = lock.newCondition();

A Condition belongs to a particular lock and is obtained from it by newCondition(). Several conditions may be created on one lock, which is what makes it more flexible than the single wait set an intrinsic monitor provides.

Please log in or register to report this question.

Loading…

Topics

    No topic!
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