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


Please Help Members By Posting Answers For Below Questions

What is the advantage of preparedstatement over statement?

560


What are 4 pillers of object orinted programming?

580


Difference between arraylist and hashset in java?

539


What is a heavyweight component?

542


Does java support multiple inheritances?

556






What are disadvantages of java?

517


What does n mean in java?

502


Assume a thread has lock on it, calling sleep() method on that thread will release the lock?

625


What is computer compiler?

533


What the difference is between execute, execute Query, execute Update?

372


What are the drawbacks of singleton class?

529


Is set sorted in java?

512


What do you understand by the term wrapper classes?

540


What are the two types of java programming?

533


What is == and === in javascript?

553