rzvika3
asked on
abstract method in interface
Hi!
In java.lang.Runable there is an abstract method: run().
Isn't it obvious that interface contains only abstract methods?
Is there a reason to that decleration?
And talking about thread, if i extends Tread, i must implement the run method although Thread implements it. why is that?
Thank you!
In java.lang.Runable there is an abstract method: run().
Isn't it obvious that interface contains only abstract methods?
Is there a reason to that decleration?
And talking about thread, if i extends Tread, i must implement the run method although Thread implements it. why is that?
Thank you!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The Runnable interface should be implemented by any class whose instances are intended to be executed by a thread. The class must define a method of no arguments called run.
The Runnable interface is provided to solve java single inheritance thread problem.
IF an object extends Thread menas it won't extend another class due to multiple inheritance.
THat's why Runnable is introduced so that a class which may extends some class and still it be a thread just be implementing Runnable interface.
Summary:
If you want a class to be thread:
A. If this class is not extending any class, use extends Thread.
B.If your class is inheriting any another class use Runnable interface.
Best of luck
ASKER
Thank you!
ASKER