Implementing Runnable Interface in Java


Implement the Runnable interface for classes whose instances are intended to be executed by a thread.

Source Code

class HelloRunnable implements Runnable {
    public void run() {
        System.out.println("Hello from a thread!");
    }
}

public class TestRunnable {
    public static void main(String[] args) {
        (new Thread(new HelloRunnable())).start();
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments