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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!