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
How is final different from finally and finalize?
Can inner class final?
Why are getters and setters used?
What will happen if a thrown exception is not handled?
What is numeric data type?
Explain when classnotfoundexception will be raised ?
Define canvas?
Differentiate between stringbuffer and string?
What are java packages?
Why can't we make a class private in java?
how we can create packages in java?
Is cout buffered?
What are the different types of inner classes?
A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.
What is array length?