Question: use the code attached to follow the instructions below: Fill in the blanks in the provided Java classes to complete the following exercise: Write a
use the code attached to follow the instructions below: Fill in the blanks in the provided Java classes to complete the following exercise:
Write a class that extends thread. The class should take as input an integer to start counting from and a String to use as a name. The run method of the threaded class should print out all the integers from start to alongside the thread's name given as a string input in the constructor
Main should create two of these threads with different names and start up both of them.
Challenge: see if you can start each thread with a value that makes them finish close to the same time.
The thread you start first is likely to finish before the other thread.
CODE:
public class Main
public static void mainString args
Create new instances of ThreadDemo:
ThreadDemo T
ThreadDemo T
Start up both ThreadDemo objects:
T;
T;
Wait on the threads to finish.
try
T;
T;
catchInterruptedException e
System.out.printlnInterrupted;
System.out.println
FINISHED
;
CODE:
public class ThreadDemo extends Thread
private int start;
private String identifier;
public ThreadDemoint start, String identifier
this.start start;
this.identifier identifier;
public void run
forint istart; i; i
System.out.printlnidentifier: i;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
