Creating Threads in Java
public class PingPONG extends Thread
{
private String word;
private int delay;
public PingPONG(String whatToSay, int
delayTime)
{
word = whatToSay;
delay = delayTime;
}
public void run()
{
try
{
for (;;)
{
System.out.print(word + " ");
sleep(delay);
}
}
catch (InterruptedException e)
{
return;
}
}
public
static void main(String[] args)
{
new PingPONG("Ping", 33).start();
new PingPONG("PONG",100).start();
}
}
No comments:
Post a Comment