Welcome Guest | Sign in | Register
Threads - Discussion Page For Q.2946 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Threads > Questions and Answers

Q: public class Threads4 {
public static void main (String[] args) {
new Threads4().go();
}
public void go() {
Runnable r = new Runnable() {
public void run() {
System.out.print("foo"); }
};
Thread t = new Thread(r);
t.start();
t.start(); }
}

What is the result?
A. Compilation fails. B. An exception is thrown at runtime.
C. The code executes normally and prints "foo". D. The code executes normally, but nothing is printed.

Answer and Explanation

Answer:An exception is thrown at runtime.

Explanation:
from go() method we are trying to create an object of Runnable interface. Actually we cannot create an object of runable interface, if you try to create then it will throw an compile time error.

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.