-3

I have written the following java code for runnable approach for creating new thread and getting errors as given below after the codes. If anyone can help me sort out this thing would be appreciated.

enter image description here

enter image description here

The errors are as follows:

enter image description here

enter image description here

Barbora
  • 921
  • 1
  • 6
  • 11
suraj j
  • 23
  • 13
  • 2
    Hey! Write the code here, don't post pictures. – akuzminykh Mar 24 '20 at 14:49
  • dont take me wrong just clarifying . r u not able to view the pic or not able to understand it through imagaes? @akuzminykh – suraj j Mar 24 '20 at 14:52
  • The code needs a lot of improvement , remove Thread creation from constructor .. FYI, you have linked images which we have to click to see the code, not helping – Sendi_t Mar 24 '20 at 15:06
  • line 22 it is not system it is System, you can't have same method with same signature in one class, and where the variable thread is coming from from also please read https://stackoverflow.com/help/how-to-ask – Abhinav Chauhan Mar 24 '20 at 15:11

1 Answers1

1

You have to pay attention to the upper and lower case of the class names. That way, "thread" becomes "thread." Also use thread#currentthread, not thread#currentthread, this method does not exist. The same goes for thread#sleep and the constructor.

Example:

public final class ThreadDemo implements Runnable {
  @Override
  public void run() {
    Thread currentThread = Thread.currentThread();

    Thread executingThread = new Thread(this, "Demo-Thread");
    executingThread.start();
    try {
      Thread.sleep(2000);
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }
  }
}

Also it is not possible to have a method 2 times in one class. So remove a run method. Also, next time I ask you to use the codeblock and no images.

Jerome Wolff
  • 356
  • 3
  • 19
  • thank u for the help. it is really appreciable that u did show interest for a downvoted question. but yeah ur answer was helpful. – suraj j Mar 25 '20 at 13:48