Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

In how many ways we can the thread? in java

Answer Posted / shaik baji

We can the Thread in two ways as follows

1) By implements the "Runnable" Interface
For Example:
class ThreadDemo implements Runnable
{
public static void main(String[] args)
{
Thread t = new Thread(new ThreadDemo());
t.start();
System.out.println("End of main thread");
}
public void run()
{
for(int i=1; i<=10; i++)
System.out.println(i);

System.out.println("End of child thread");
}

}



2) By extents the "Thread" class
NOTE: Thread is not a abstract class.

For Example:
------------

class ThreadDemo extends Thread
{
public static void main(String[] args)
{
Thread t = new ThreadDemo();
t.start();
System.out.println("End of main thread");
}
public void run()
{
for(int i=1; i<=10; i++)
System.out.println(i);

System.out.println("End of child thread");
}

}

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is this () in java?

1006


what is the difference between the methods sleep() and wait()? : Java thread

949


What class of exceptions are generated by the java run-time system?

1155


What is a private class in java?

1032


What is stringjoiner ?

943


What is the difference between an inner class and a sub-class?

986


List primitive java types?

1016


What is package protected in java?

964


Write a program to print 15 random numbers using foreach of java 8?

914


What is the use of StringTokenizer class?

1049


What is output buffer?

1024


Difference between static binding and dynamic binding?

1087


what r advatages of websphere? & how to deploy?

2166


How to disable caching on back button of the browser?

1059


What is polymorphism java example?

989