What can be a result?

Given:

1. public class TestOne implements Runnable {
2. public static void main (String[] args) throws Exception {
3. Thread t = new Thread(new TestOne());
4. t.start();
5. System.out.print(“Started”);
6. t.join();
7. System.out.print(“Complete”);
8. }
9. public void run() {
10. for (int i = 0; i < 4; i++) {
11. System.out.print(i);
12. }
13. }
14. }

What can be a result?

Given:

1. public class TestOne implements Runnable {
2. public static void main (String[] args) throws Exception {
3. Thread t = new Thread(new TestOne());
4. t.start();
5. System.out.print(“Started”);
6. t.join();
7. System.out.print(“Complete”);
8. }
9. public void run() {
10. for (int i = 0; i < 4; i++) {
11. System.out.print(i);
12. }
13. }
14. }

What can be a result?

A.
Compilation fails.

B.
An exception is thrown at runtime.

C.
The code executes and prints “StartedComplete”.

D.
The code executes and prints “StartedComplete0123”.

E.
The code executes and prints “Started0123Complete”.



Leave a Reply 0

Your email address will not be published. Required fields are marked *