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

Threads - General Questions Questions and Answers

41.

Which of these types is an interface?

Answer: A

Runnable is an interface with a single method. Thread, ThreadGroup and ThreadLocal are all classes, which is why a task class implements the first and extends any of the others only when it genuinely needs their behaviour.

Please log in or register to report this question.

Answer: B

ThreadLocal is a generic class instantiated with new, and its type argument is what get and set exchange. There is no factory on Thread, and get is an instance method returning the stored value rather than a constructor.

Please log in or register to report this question.

43.

Which of these is the correct package for the Lock interface?

Answer: C

Lock, ReentrantLock, ReadWriteLock and Condition all sit in java.util.concurrent.locks, a subpackage of the main concurrency package. Importing java.util.concurrent alone does not bring them in, because an import on demand does not reach subpackages.

Please log in or register to report this question.

Answer: D

AtomicInteger is an ordinary class taking an optional initial value, and both the zero-argument and int-argument constructors exist, so two of these compile. The one shown is the clearer of the pair because it states the starting value. Java has no atomic keyword.

Please log in or register to report this question.

46.

Which of these is the correct way to convert a duration for ExecutorService.awaitTermination?

Answer: B

The concurrency utilities take a numeric amount together with a TimeUnit constant, rather than assuming milliseconds the way the older Thread methods do. The unit is an enum value, not a String, so a typo is caught at compile time.

Please log in or register to report this question.

Answer: C

await declares InterruptedException, so a caller must either catch it or declare it, and the class is named InterruptedException in full. There is no catches clause in Java; handling happens inside the body with try and catch.

Please log in or register to report this question.

48.

Which method must be provided when extending Thread to give it work?

Answer: D

Thread's own run does nothing useful unless a Runnable was supplied, so a subclass overrides run to hold the work. start is inherited and should not be overridden, execute belongs to Executor, and call belongs to Callable.

Please log in or register to report this question.

49.

Which of these correctly installs a handler for exceptions escaping a single thread's run method?

Answer: A

setUncaughtExceptionHandler is an instance method taking a Thread.UncaughtExceptionHandler. The static counterpart is setDefaultUncaughtExceptionHandler, which takes only the handler and applies to every thread without one of its own.

Please log in or register to report this question.

50.

Which of these is a static method of Thread?

Answer: B

Correct answer: dumpStack

Thread.dumpStack() prints a stack trace of the current thread, so like sleep and yield it concerns whoever is executing and is static. getName, getStackTrace and setUncaughtExceptionHandler all act on a named thread and are instance methods.

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