Thread in java



A thread is a executing the code within the program. Thread is a most important topic.Because thread is used to gaming. If you want Full Explain click the link Multithread.








Example-1
class A extends Thread
{
      public void run()
      {
          System.out.print("Class A");
      }
}

public class Main
{
      public static void main(String[] args) 
      {
          A obj = new A();

          obj.start();
      }
}


Output



Class A








Example-2
class A implements Runnable
{
      public void run()
      {
           System.out.print("Class A");
      }
}

public class Main
{
      public static void main(String[] args) 
      {
           Runnable obj = new A();

           Thread t = new Thread(obj);

           t.start();
      }
}


Output



Class A