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"); }

/ 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 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({""});

Showing Answers 1 - 3 of 3 Answers

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions