why Runnable interface is preferable than extending the
Thread class?
Answers were Sorted based on User's Feedback
Answer / suresh
u know that java not supporting multiple inheritance.if u
extend thread class,u can't extend any class which you
required other than thread class.if u are implementing
runnable interface u can extend any class which you required
other than thread class.this is main advantage of
implementing runnable interface.
Is This Answer Correct ? | 115 Yes | 13 No |
Answer / susheeel
Many Java programmers feel that classes should be extended
only when they are enhanced or modified in some way.So,if
you will not be overriding any of Thread's other methods,it
is probably best simply to implement Runnable.
Is This Answer Correct ? | 32 Yes | 5 No |
is this prefable why simple
you class A extends other class B
and it also want to be a thread then what you should
beacuse its allow in java that one class extends two class
its not possible in java
class A
{
}
class B extends A
{
}
then what to do to make the thread of class B
so you are going to extends the Thread class too
its biggest blunder in java so you should to prefer
implements the Runnable interface
that it not just the f--k above mention though my ther frnds
thanks imagie
class B extends A implements Runnable
{
public void run()
{
}
}
class C
{
public static void main(String []args)
{
C c = new C();
B b = new B();
Thread t1 = new Thread(b);
t1.start();
}
}
}
and another reason to implements the Runnable interface
when you want to allocate some specific work means to say
that you just whe the thead will create and run ,through the
run method which you define in this class do some
when the thread runs means to say that when you extends
Thread and you not define the run method the default will
run
and when you implements the Runnable you must and needs to
define it do some functionaklity on each thread creation
thanks amitsing2008@gmail.com
amit09mca
Is This Answer Correct ? | 11 Yes | 3 No |
imolimen Runnabule inerface and extends Thread functionally
both are same.But implimenting RunnebleInterface more
advantage because of there is possibility extends more then
one class and also we can override run() only once.
Is This Answer Correct ? | 10 Yes | 4 No |
Answer / praveen gupta
The main reason to implement Runnable interface is that you know that java does not supporting multiple inheritance
through classes .if u extend Thread class,u can't extend any
class which you required other than thread class.if u are
implementing runnable interface u can extend any class which
you required other than thread class.this is main advantage of
implementing java.lang.Runnable interface.
Is This Answer Correct ? | 4 Yes | 0 No |
Answer / srinu
you know that java does not supporting multiple inheritance
through classes .if u extend Thread class,u can't extend any
class which you required other than thread class.if u are
implementing runnable interface u can extend any class which
you required other than thread class.this is main advantage of
implementing java.lang.Runnable interface.
Is This Answer Correct ? | 6 Yes | 3 No |
Answer / myluvdeepu
if we extend thread then we can't extend other class.
but if we implement runnable interface we can implement as much interface as we can, there is no restriction.
thread call the run method automatically(if called with no-arg).but for runnable we need to call run method.
thread cause problem in multiple inheritance.
but runnable interface don't.
Is This Answer Correct ? | 4 Yes | 9 No |
What is the basic concepts of OOPS?
How would overload a function based on return type?
What is the difference between throw and throws keywords?
What is functional interface in java?
Which is illegal identifier in java?
Explain the difference between string, stringbuffer and stringbuilder in java?
How do you do math powers in java?
How to initialize an Applet ?
Can we use catch statement for checked exceptions when there is no chance of raising exception in our code?
What is the main use of java?
What is an object-oriented paradigm?
Features of Java?