Java OCA OCP Practice Question 2504

Question

What is the output of the following code?

1. public class Main implements Runnable {
2.     public void run() {
3.         System.out.println("abc");
4.         start();
5.     }
6.     public static void main(String... args) {
7.         new Thread(new Main()).start();
8.     }
9. }
  • a It prints abc once.
  • b It prints abc multiple times.
  • c Compilation error
  • d Runtime exception


c

Note

Class Main implements the Runnable interface; it doesn't extend class Thread.

So it doesn't have access to method start().

Calling start() at line 4 results in the compilation failure.




PreviousNext

Related