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

Discussion

Consider implementing Runnable rather than extending Thread. Which statement is correct?

  • A.Implementing Runnable is required whenever more than one thread is created.
  • B.Implementing Runnable leaves the class free to extend something else.
  • C.Extending Thread leaves the class free to extend something else.
  • D.Both approaches are interchangeable.

Answer: B

Java allows a class only one superclass, so extending Thread spends it. Implementing Runnable keeps that slot free and separates the work from the machinery that runs it, which is why it is usually preferred. Either approach can create any number of threads.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.