We have two methods to create methods the threads.
1. Implementing runnable interface
2. Extending to thread class and overriding run method.
Among these two which one is better and why?
Please explain me in detail.

Answers were Sorted based on User's Feedback



We have two methods to create methods the threads. 1. Implementing runnable interface 2. Extending..

Answer / venkat

implementing runnable interface is better than extending to
thread why because if u implements from runnable interface u
can have chance to extend one more class.but incase of
extending thread this facility is not there

Is This Answer Correct ?    5 Yes 0 No

We have two methods to create methods the threads. 1. Implementing runnable interface 2. Extending..

Answer / mira

The Runnable technique is particularly convenient when you
want to create just a single thread to carry out a specific
task. The run() method will have access to the instance
variables in the Runnable object. For example, a common
approach to applet animation is to make the applet
Runnable. The run() method then has access to the applet's
variables, which could be parameters passed in the applet
tags or set by the user via the graphical interface.

Note also that since there are no restrictions on the
number of interfaces that a class can implement, it is easy
to add Runnable to a class.

On the other hand, if you want to create multiple threads,
then it usually makes more sense to use a Thread subclass.
This helps to better conceptualize the threads as
independent objects, each with its own independent sets of
variables (as opposed to sharing variables in the Runnable
object.) You can set the values of whatever parameters they
need via their constructors or "setter" methods.

Is This Answer Correct ?    0 Yes 2 No

Post New Answer

More Core Java Interview Questions

Is .net better than java?

0 Answers  


What does main method?

0 Answers  


What language is java written?

0 Answers  


Explain list interface?

0 Answers  


how to connect one jsp page to another jsp page????

6 Answers   IIT, Symphony,






What's the difference between comparison done by equals method and == operator?

0 Answers  


write a program to create an vector and listeterator.and value should be enter through keyboard.

1 Answers   Axcend,


What is a generic type?

0 Answers  


Can main() method in java can return any data?

0 Answers  


what is private constructor?what are the uses of writing private constructor in our program?

10 Answers  


Write a java program to generate fibonacci series ?

0 Answers   Cyient,


What is data type example?

0 Answers  


Categories