java4all@1986 java. Powered by Blogger.

Among runnable Interface (or) Thread class which one is preferable?

>> Monday, May 30, 2011

The Runnable interface is preferred, as it does not require your
object to inherit a thread because when you need multiple inheritance, only interfaces can help you. In the above
example we had to extend the Base class so implementing Runnable interface is an obvious choice. Also note
how the threads are started in each of the different cases as shown in the code sample.
In an OO approach you should only extend a class when you want to make it different from it’s superclass, and change it’s behavior. By
implementing a Runnable interface instead of extending the Thread class, you are telling to the user that the class
Counter that an object of type Counter will run as a thread.

0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP