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

Is a copy constructor?

997


What is thread synchronization in java?

857


Can we use String with switch case?

1107


What are the advantages of inner classes?

941


What is time complexity algorithm?

987


Can we sort hashset in java?

1034


What is the difference between throw and throws keywords?

986


How is abstraction implemented in java ?

918


What is the equal sign?

1027


When wait(), notify(), notifyall() methods are called does it releases the lock or holds the acquired lock?

935


Is int a class in java?

939


What does it mean to flush a file?

1001


What do you understand by abstract classes?

1014


What is lossy conversion in java?

1115


What is a functional interface?

963