Runnable Interface and its methods


Runnable Interface
  • Runnable Interface consists only method. i.e. run()
  • Synatx: public interface Runnable
  • Use:
    • 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.
    • This interface is designed to provide a common protocol for objects that wish to execute code while they are active. 
    • For example, Runnable is implemented by class Thread. 

  • Example:
Method
  • run:
    • Syntax: public void run()
    • Use
      • If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
      • Subclasses of Thread should override this method.
    • Example: new Thread(object1).run();

Thanks a lot for query or your valuable suggestions related to the topic.

Previous Post Next Post

Contact Form