Menu Bar

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, 22 November 2016

Choosing Best Approach Among Implementing Runnable Interface or entends Thread Class.

Previously we have discussed about

Java provides two ways to create a child threads first is by implementing a Runnable Interface and second is by extending the Thread class.Now one questions comes in mind which approach is better.

* The limitations with extends thread is that if you extend the Thread class , you can not extend any other class, because java does not supports multiple inheritence. On other hand if you implement the Runnable Interface you can also extends any class.

* Implements Runnable makes the code loosely-coupled and easier to read. Because the code is split into two classes.while "extends Thread"  makes the code tightly coupled because , Single class contains the thread code as well as the code that needs to be done by the thread.

Example Implementing Runnable Interface:

public class Test implements Runnable{

@Override
public void run() {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
}
}

Example Extends Thread Class:

public class Test extends Thread {

public void run() {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
}
}


      
Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.



Share this Blog with yours Friends !!

No comments:

Post a Comment