Why does a compilation error occur when calling the start method?

My program is

class RunnableA implements Runnable{
    public void run(){
        System.out.println("Program A");
    }
}
class MyThread extends Thread{

}
class Demo{
    public static void main(String args[]){
        RunnableA a1=new RunnableA();
        a1.start(); 

    }
}

And I got this when compiling.

Demo.java:12: error: cannot find character

+4
source share
1 answer

startis a class method Thread, not a Runnable interface method.

Here you can run Thread, which will run your Runnable logic:

class Demo {
    public static void main(String args[]){
        RunnableA a1=new RunnableA();
        new Thread(a1).start(); 
    }
}
+3
source

All Articles