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

Answers were Sorted based on User's Feedback



In how many ways we can the thread? in java..

Answer / himanshu kapoor

IF this question is that in how many ways we can use the thread in java?, then answer is that there are two ways
1. by implementing Runnable interface and
2. by inheriting Thread (abstract class)

Is This Answer Correct ?    24 Yes 3 No

In how many ways we can the thread? in java..

Answer / 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

In how many ways we can the thread? in java..

Answer / virendrasinh gohil

The only way to create a thread is using a thread class.
(Either by extending it or creating object elsewhere).
Runnable does very little contribution here. It's just
that, the thread object expects instance of a class which
should have run() (semantics) method and is called via
runnable interface. Runnable method doesn't create any
thread by itself (sounds dumb as everybody knows Runnable
is an interface).

Calling Thread's start() is the only way in java to spawn a
separate independed execution with in the application.

Is This Answer Correct ?    5 Yes 0 No

Post New Answer

More Core Java Interview Questions

what is abstract class in Java?

0 Answers   Hexaware, Syntel,


strings in java are objects.why?

2 Answers  


What is the difference between notify and notifyall method?

0 Answers  


List out five keywords related to exception handling ?

0 Answers  


What are predicates in java 8?

0 Answers  


What is primitive array?

0 Answers  


wht is customised exception?

1 Answers   Logica CMG, Novell, Prudential,


what is meant by multicast?

1 Answers  


Keywords in Exceptions?

2 Answers  


What is javac used for?

0 Answers  


What is thread pool? How can we create thread pool in java?

0 Answers  


What exactly is a .class file?

0 Answers  


Categories