why Runnable interface is preferable than extending the
Thread class?
Answer Posted / amit singh
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 |
Post New Answer View All Answers
Is double bigger than float?
Name few java util classes introduced with java 8 ?
What is arguments in java?
Why stringbuilder is not thread safe?
What are the advantages of exception handling?
What is navigable map in java?
What is a dot notation?
What is double word?
Which class is the superclass for all the classes?
What is the maximum size of hashmap in java?
Name few "optional" classes introduced with java 8 ?
What kind of variables can a class consist?
What does three dots mean in java?
What is an argument in java?
What is annotation in java?