wellnwill Marathahalli Bangalore

Thread class method

public void start();
public void run();

Inside Runnable interface, abstract run() method is available.

abstract public void run();
class Thread1 extends Thread
{
 }
class Test011
{
public static void main(String[] args)
{
 Thread1 t1=new Thread1();
 t1.start();
}
}
//O/P-blank





class Thread1 extends Thread
{
  public void run()
 {
  System.out.println("working for Thread");
 }
}
class Test012
{
public static void main(String[] args)
{
 Thread1 t1=new Thread1();
 t1.start();
}
}
//O/P-working for Thread

class Thread1 extends Thread
{
 }
class Test011
{
public static void main(String[] args)
{
 Thread1 t1=new Thread1();
 t1.start();
}
}
//O/P-blank





class Thread1 implements Runnable
{
  public void run()
 {
  System.out.println("working for Thread");
 }
}
class Test014
{
public static void main(String[] args)
{
 Thread1 t1=new Thread1();//t1 is a type of Runnable.
   t1.start();
}
}
//O/P-CTE-cannot find symbol t1.start().

class Thread1 implements Runnable
{
  public void run()
 {
  System.out.println("working for Thread");
  System.out.println("Thread name:"+Thread.currentThread());
 }
 public void start()
 {
	 //this start method will not create new stack.
	 //Thread class start method will create new stack.
  this.run();
 }
}
class Test015
{
public static void main(String[] args)
{
 Thread1 t1=new Thread1();
//t1 is a type of Runnable.
   t1.start();
}
}
//O/P- working for thread
    Thread name:Thread [main,5,main]
class Thread1 implements Runnable
{
  public void run()
 {
  System.out.println("working for Thread");
 }
}
class Test014
{
public static void main(String[] args)
{
 Thread1 t1=new Thread1();//t1 is a type of Runnable.
   t1.start();
}
}
//O/P-CTE-cannot find symbol t1.start().









class Thread1 implements Runnable
{
  public void run()
 {
  System.out.println("working for Thread");
  System.out.println("Thread name:"+Thread.currentThread());
 }
}
class Test016
{
public static void main(String[] args)
{
 System.out.println("Thread name:"+Thread.currentThread());
 Thread1 t1=new Thread1();//t1 is a type of Runnable.
 Thread t=new Thread(t1);//t is a type of Thread.
 t.setName("Robert");
   t.start();
}
}




class Thread1 implements Runnable
{
 public void run()
 {
  System.out.println("working for Thread");
 }
}
class Test
{
public static void main(String[] args)
{
 Thread1 t1=new Thread1();
 Thread t=new Thread(t1);
 t.start();
 t.setName("Thread1");
 System.out.println("Thread name:"+t.getName());
 t.setPriority(3);
 System.out.println("Thread priority:"+t.getPriority());
}
}
//O/P-Thread name:Thread1
      Working for Thread
      Thread priority: 3
Footer with Map