Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider the following Thread class: public class Dog extends Thread { private int id; // thread id public Dog (int id){ this.id=id; } public void
Consider the following Thread class:
public class Dog extends Thread {
private int id; // thread id
public Dog (int id){
this.id=id;
}
public void run(){
while (true){
System.out.println("woof...woof...from dog " + id);
try{sleep(2000);}//sleep for 2 seconds
catch(InterruptedException e) {}
}
}
}
Show a Java code fragment for the following task:
First, instantiate an array object named Pack consisting of sixty Dog objects.Then, create & execute all the Dog threads in Pack, assigning thread ids in the range 0 to 59
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started