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
What is a java applet? What is an interface?
Is it necessary for the port addresses to be unique? Explain with reason.
Does .length start 0 java?
What are byte codes?
What is java util collection?
Can you add null to a list java?
What is var keyword ?
Is empty list java?
Given a singly linked list, determine whether it contains a loop or not without using temporary space?
What is thread pool? How can we create thread pool in java?
Can we use String with switch case?
What is skeleton and stub?
What java is used for?
what are abstract functions?
Can I import same package/class twice?