JP-4

 

  1.  Creating Threads

Code:

public class StartExp1 extends Thread

{

public void run()

{

for(i=0;i<=6;i++)

{

   System.out.println(i);

}

}

  public static void main(String[] args)

{

   StartExp1 t1= new StartExp1();

   t1.start();

}

}


Output:


  1.  By implementing Runnable Interface

Code:

public class StartExp2 implements Runnable

{

public void run()

{

   System.out.println("Threading is running...");

}

public static void main(String[] args)

{

   StartExp2 m1= new StartExp2();

   Thread t1= new Thread(m1);

   t1.start();

}

}


Output:


Comments

Popular posts from this blog

python(BI)

Prac_8(AMP)

LSA10