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 functional interface in javatpoint?
What are register variables what are the advantages?
What is the base class in java from which all classes are derived?
When we serialize an object does the serialization mechanism saves its references too?
how we can create packages in java?
Tell us something about different types of casting?
What is super keyword explain with example?
Can we store variables in local blocks?
Why Set interface contains unique elements, what internally implemented for this so that it contains unique elements?
What is Major and importance difference between for and foreach loop ?
What is java algorithm?
What is character in data type?
Can we convert list to set in java?
What is meant by the value of a variable?
Can a class be declared as static?