日期:2014-05-20 浏览次数:20685 次
public class BankDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Cus c=new Cus();
Thread t1 = new Thread(c);
Thread t2 = new Thread(c);
t1.start();
t2.start();
}
}
class Bank
{
private int sum;
public void add(int n)
{
sum=sum+n;
System.out.println("sum="+sum);
}
}
class Cus implements Runnable
{
private Bank b=new Bank();
public void run()
{
for(int i=0;i<3;i++)
{
b.add(100);
}
}
}