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

Discussion

Which of these assignments compiles?

  • A.Thread t = new Runnable();
  • B.Runnable r = new Runnable();
  • C.Thread t = new Object();
  • D.Runnable r = new Thread();

Answer: D

Thread implements Runnable, so a Thread reference is assignable to a Runnable variable. Runnable is an interface and cannot be instantiated directly without a body, and an Object is not a Thread so the last assignment needs a cast that would fail at runtime anyway.

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

Post your comment

Please log in or register to post a comment.