2
Reply

What is Runnable interface in Java?

Rohit Gupta

Rohit Gupta

5y
2.8k
0
Reply

    The runnable interface must be implemented by any class, whose instances are intended to be executed by a thread. The Runnable interface has only one run() method.

    public void run()

    This method is used to perform an action for a thread.

    For a detailed tutorial on Java MultiThreading, visit
    https://www.c-sharpcorner.com/article/a-complete-multithreading-tutorial-in-java/

    Java runnable is an interface used to execute code on a concurrent thread. It is an interface which is implemented by any class if we want that the instances of that class should be executed by a thread.

    public class ExampleClass implements Runnable {

    1. @Override
    2. public void run() {
    3. System.out.println("Thread has ended");
    4. }
    5. public static void main(String[] args) {
    6. ExampleClass ex = new ExampleClass();
    7. Thread t1= new Thread(ex);
    8. t1.start();
    9. System.out.println("Hi");
    10. }

    }