Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot implement run() in Runnable

public class Reader extends Thread{

...

    public static void run()throws InterruptedException{

        Monitor mon = new Monitor();

            for(int i = 0; i <10; i++)
            {
                mon.MonEntry();



                Read("file.txt");

                mon.MonExit();
            }

    }
}

I cannot use extends Thread for some reason because it says: cannot implement run() in Runnable. I don't see what I did wrong? When we call extends Thread instead of implement Runnable shouldn't we be able to use our own implementation of run() for starting threads?

like image 372
user2824983 Avatar asked Feb 04 '26 17:02

user2824983


1 Answers

It is just a public void. No static.

Please, have a look at the documentation. It clearly shows that it is public void :-)

Also, avoid the name Reader because there is a class in java.io package which is named Reader and using names that are already present in Java packages is discouraged :)

like image 176
An SO User Avatar answered Feb 06 '26 07:02

An SO User



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!