What will be the output of the following Java code?

class newthread implements Runnable
   {
   Thread t;
   newthread()
       {
       t = new Thread(this,"My Thread");
       t.start();
   }
   }
   class multithreaded_programing
   {
       public static void main(String args[])
       {
           new newthread();        
       }
   }

a) My Thread
b) Thread[My Thread,5,main]
c) Compilation Error
d) Runtime Error

1 thought on “What will be the output of the following Java code?”

  1. c
    Explanation: Thread t has been made by using Runnable interface, hence it is necessary to use inherited abstract method run() method to specify instructions to be implemented on the thread, since no run() method is used it gives a compilation error.
    Output:
    $ javac multithreaded_programing.java
    The type newthread must implement the inherited abstract method Runnable.run()

Leave a Comment