Code: Select all
class Hello implements Runnable{
int i;
public void run(){
try
{
Thread.sleep(3000);
}
catch (InterruptedException e){}
i = 20;
}
}
public class T5
{
static public void main(String[] args) throws Exception{
Hello h = new Hello();
Thread t = new Thread(h);
t.start();
t.join();
System.out.println("h.i = " + h.i);
}
}
Code: Select all
class ThreadTest implements Runnable{
public void run(){
try{
Thread.sleep(1000);
}
catch(InterruptedException e){
System.out.println("Interrupted ");
}
}
public static void main(String [] args) throws Exception{
ThreadTest h = new ThreadTest();
Thread t = new Thread(h);
t.setName("Billy");
t.start();
t.join();
}
}