public class Test extends Thread {
static int n = 0;
private int startNum = 0 ;
public Test (int sn)
{
this.startNum = sn ;
}
public static synchronized void addSum (int num)
{
n += num ;
}
public static void main(String[] args) {
Thread [] thList = new Thread [10] ;
for (int i = 0; i < 10; i ++) {
thList [i] = new Test(i * 10 + 1) ;
thList [i].start();
}
for (int i = 0 ; i < 10 ; i ++)
{
thList [i].join () ;
}
System.out.println ("Sum is : " + n) ;
}
public void run() {
int sum = 0 ;
for (int i = 0; i < 10; ++i) {
sum += sn + i ;
}
addSum (sum) ;
}
}