1.

Explain The Method Of Thread Class With Example.

Answer»
  • In this METHOD of creating thread, we have to extend the Thread class and override the run() method in our class to create a Thread.
  • We have to create an object of the our class.
  • Once the object is CREATED then we have to invoke the start() method and it will generate a new thread of execution.

For example
PUBLIC class MyThread EXTENDS Thread

{
public void run()
{
// code to execute under the thread
}
public STATIC void main(String [] args)
{
MyThread c = new MyThread();
c.start();
}
}

For example
public class MyThread extends Thread

{
public void run()
{
// code to execute under the thread
}
public static void main(String [] args)
{
MyThread c = new MyThread();
c.start();
}
}



Discussion

No Comment Found