Why do I get a compile error when calling start method?

Lama Haris

My program -

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 symbol

Eran

start is a method of Thread class, not a method of the Runnable interface.

Here's a way to start a Thread that would run your Runnable's logic :

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive