user2824983
user2824983

Reputation: 63

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?

Upvotes: 3

Views: 3548

Answers (2)

Scientist
Scientist

Reputation: 1464

run method inside Thread class is not static

Upvotes: 1

An SO User
An SO User

Reputation: 24998

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 :)

Upvotes: 12

Related Questions