Skip to content

The method start() is undefined for the type Runnable

I am learning java 8 with anonymous classes, i cant find start method, am i doing something wrong here?

class Tester {
    void doWork() {
        Runnable r = new Runnable() {

            public void run() {
        r.start(); // showing ERR The method start() is undefined for the type Runnable

this works fine,

// Here we can extends any other class 
class Test extends Geeks implements Runnable { 
    public void run() 
        System.out.println("Run method executed by child Thread"); 
    public static void main(String[] args) 
        Test t = new Test(); 
        Thread t1 = new Thread(t); 
        System.out.println("Main method executed by main thread"); 



That’s because you need to start Threads – but you only need to run Runnables.

A thread makes it run in parallel (kind of) to the currently executing thread. A runnable just runs in the current thread. You can pre-populate a Thread with a runnable when you create it and then run it – the start() method in the Thread will call run().

You can simply go Test t = new Test();; and it will execute in the current Thread.

7 People found this is helpful