Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.
The following code defines the ThreadSample class. public class ThreadSample implements Runnable { public static void main(String args[]) { System.out.println("This is the ThreadSample object"); }
public class ThreadSample implements Runnable {
public static void main(String args[]) {
System.out.println("This is the ThreadSample object");
}
public void run() {
while (true) {
try {
Thread.sleep(100);
System.out.println("Thread ran.");
} catch (Exception e) {}
}
Referring to the sample code above, how do you start an instance of ThreadSample in a new thread?
Choice 1
Thread.start(new ThreadSample());
Choice 2
Thread.new(ThreadSample);
Choice 3
new ThreadSample().run();
Choice 4
new Thread(new ThreadSample()).start();
Choice 5
new ThreadSample().main({""});
Related Answered Questions
Related Open Questions