Wednesday, 21 October 2015

Implementing threads in java


public class First {

public static void main(String[] args) {
// TODO Auto-generated method stub
Sec obj = new Sec();
Thread t = new Thread(obj);
t.start();
}

}


public class Sec extends Thread{

public void run(){
for(int i=0;i<10;i++){
System.out.println("The value of i is " +i);
}
}
}

output:-
The value of i is 0
The value of i is 1
The value of i is 2
The value of i is 3
The value of i is 4
The value of i is 5
The value of i is 6
The value of i is 7
The value of i is 8
The value of i is 9

No comments:

Post a Comment