Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Interview-Questions Difference between extends thread class vs implements runnable interface
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Rajendra
Difference between extends thread class vs implements runnable interface
2 Answer(s)      5 years and 3 months ago
Posted in : Java Interview Questions



Advertisement
View Answers

October 1, 2009 at 5:35 PM


Hi Friend,

Difference:

1)If you want to extend the Thread class then it will make your class unable to extend other classes as java is having single inheritance feature whereas If you implement runnable interface, you can gain better object-oriented design and consistency and also avoid the single inheritance problems.

2)Extending the thread will give you simple code structure in comparison to Runnable Interface.

3)Using Runnable Interface, you can run the class several times whereas Thread have the start() method that can be called only once.

Thanks


July 24, 2012 at 10:49 AM


The main difference between extending a Thread class and implementing the Runnable interface is, Extending the Thread class:When your class is extending the Thread class then your class becomes a single thread which is inheriting all the properties and characteristics of the Thread class and it becomes heavy. Implementing the Runnable interface:When your class implements the Runnable interface then you only override the run() method,but you create one or more instance(s) of the Thread class in that instance you pass the instance of your Runnable interface implemented class and then you apply the start() method on the Thread instance.So this instance(s) creates a seperate Thread(s) and every individual Thread runs seperately but not as a single heavy Thread in your program.



Related Tutorials/Questions & Answers:
Difference between extends thread class vs implements runnable interface - Java Interview Questions
Difference between extends thread class vs implements runnable interface  Hi Friends, can you give difference between extending thread class... Runnable Interface, you can run the class several times whereas Thread have
implements runnable n extends thread - Java Beginners
implements runnable n extends thread  what is the difference between implements runnable n extends thread? public class...(); class StringThreadImplement implements Runnable { private String } }  Hi public class
Advertisements
what is the difference between extends and implements
what is the difference between extends and implements  difference between extends and implements
what is the difference between extends and implements
what is the difference between extends and implements  difference between extends and implements
Diff between Runnable Interface and Thread class while using threads
Diff between Runnable Interface and Thread class while using threads  Diff between Runnable Interface and Thread class while using threads   Hi Friend, Difference: 1)If you want to extend the Thread class
Diff between Runnable Interface and Thread class while using threads
Diff between Runnable Interface and Thread class while using threads  Diff between Runnable Interface and Thread class while using threads   Hi Friend, Difference: 1)If you want to extend the Thread class
Difference between abstract class and an interface
Difference between abstract class and an interface The difference between... between abstract class and interface in java. Abstract class is a class... search for overridden methods. There is no any difference between a interface
What are the difference between abstract class and interface?
What are the difference between abstract class and interface?  What are the difference between abstract class and interface
Difference between Timer and Thread?
Difference between Timer and Thread?  Can anyone tell me about the difference between Timer and Thread, Why we need to have Timer in case we have Thread implimentation startegy in Java
Interface vs abstract class
Interface vs abstract class  Hai, Is there any possible to defining abstract methods in Interface
Runnable interface in java
In this section we will learn about Runnable interface in java. In java thread are created by two ways, one by extending Thread class and another one by implementing Runnable interface
Java Thread and Runnable
Java Thread and Runnable  What's the difference between Thread and Runnable types
about implements and extends - Java Beginners
about implements and extends  hello, class A extends B implements c // this is valid statement class A implements c extends B // this is invalid... A extends B implements C but class A implements C extends B is invalid plz explain
difference between main thread and child thread?
difference between main thread and child thread?  any one give correct exact difference.   in jsp 7 implicit objects are available those are 1:response->This denotes the data included with the HTTP Response. 2
difference between enum and final class?
difference between enum and final class?  what is the difference between enum and final class in java?   The java.lang.Enum is an abstract.... The definition of Enum is: public abstract class Enum> extends Object implements
Interface Vs Abstract Class
Interface Vs Abstract Class       There are three main differences between an interface and an abstract..., an interface is equivalent to a fully abstract class (a class with only public abstract
what is the difference between moqui framework vs other frameworks
what is the difference between moqui framework vs other frameworks  HI Can you share what is the difference between Moqui framework vs other frameworks
Java : Runnable Thread
. After creating class that implements Runnable interface, you can create object... by using Runnable interface. class RunnableThread implements Runnable... a thread by implementing the Runnable interface. You need to implement a single
Java Runnable Interface
is an interface. Thread class implements it. Java has multithreading facility. Thread is also created by implementing the Runnable interface. Java Runnable Thread Example public class runnable1 implements Runnable { @Override
can we use class in jsp which implements interface
can we use class in jsp which implements interface   can we use class in jsp which implements interface
Difference between GenericServlet and HttpServlet
In this section we will discuss about the difference between GenericServlet and HttpServlet. GenericServlet is an abstract class that extends java.lang.Object while HttpServlet is an abstract class that extends GenericServlet
Difference between the local and class variable.
class. Below two program are shown which help you to understand the difference between the class and local variable. Showing Local Variable...Description: The class variable are declared in the class but not within
Difference between Java IO Class - Java Beginners
Difference between Java IO Class  What is the difference in function between Two set of Stream class as mention below- 1)FileInputStream & FileOutPutStream vs. 2)InputStreamReader & OutputStreamWriter
difference between marker and tag interface - Java Interview Questions
. A class implements this interface to indicate that its non-transient data members can...difference between marker and tag interface  what is the difference between marker interface and tag interface?  Hi friend, nterface
Threads on runnable interface - Java Beginners
.  Hi class MyThread extends Thread{ MyThread(String s...Threads on runnable interface  need a program.....please reply asap Create 2 threads using runnable interface.First threads shd print "hello
Threads on runnable interface - Java Beginners
.  Hi manshi, i am sending simple code of thread. class MyThread extends Thread{ MyThread(String s){ super(s); start...Threads on runnable interface  need a program.....please reply asap
Interface and Abstract class
Interface and Abstract class  Difference between Interface and Abstract class? Give some example   Difference Between Interface and Abstract Class 1)Main difference is methods of a Java interface are implicitly
What is the difference between a static and a non-static inner class?
What is the difference between a static and a non-static inner class?   Hi, What is the difference between a static and a non-static inner class? Thanks
What’s the difference between accessing a class method via -> and via ::?
What?s the difference between accessing a class method via -> and via ::?  What?s the difference between accessing a class method via -> and via
Java Interview Questions - Page 5
;extends" Thread class. Second, making your class "implements" Runnable interface. Put jobs in a run() method and call start() method... is started, via its start() method of the Thread class, the JVM invokes
Difference between class,name,id attributes in each JSP tag
Difference between class,name,id attributes in each JSP tag  Can i know the difference between class,name,id attributes in each JSP tags.................. These 3 are only used for reference ..... And what are the differernces
Advertisements
 

 

 

DMCA.com