// Sum1.java class SumThread extends Thread { private int from, to, sum; public SumThread(int from, int to) { this.from = from; this.to = to; sum = 0; } @Override public void run() { for (int i = from; i <= to; i++) { sum += i; } } public int getSum() { return sum; } } public class Sum1 { public static void main(String args[]) { SumThread t1 = new SumThread(1, 5000); SumThread t2 = new SumThread(5001, 10000); t1.start(); t2.start(); System.out.printf("The sum of 1-1000 is %d.\n", t1.getSum() + t2.getSum()); } }