//主函数
class test
{
public static void main(String[] args)
{
Bank b = new Bank();
new Thread(new out(b)).start();
new Thread(new put(b)).start();
}
}
//Bank类中有name和mony属性以及对应的set get方法
class Bank
{
String name;
int mony;
public synchronized void setBank(String name,int mony)
{
this.name = name;
this.mony = mony;
}
public synchronized void getBank()
{
//Sop.sop()是我定义的System.out.println()类,看过毕老师视频的同学,你们懂得……
Sop.sop(name+"........"+mony);
}
}
// out类主要是输出Bank类中的name 和 mony
class out implements Runnable
{
Bank b;
out(Bank b)
{
this.b = b;
}
public void run()
{
while(true)
{
b.getBank();
}
}
}
//put 类 这个是问题的关键
class put implements Runnable
{
Bank b;
put(Bank b)
{
this.b = b;
}
public void run()
{
// 这里: 我想每次运行的时候判断,如果Bank的name是ZhangSan 那就将LiSi 赋给他
//但是输入结果一直是null..........0,求解呀~~这个判断语句有错么???
while(true)
{
if(b.name.equals("ZhangSan"))
{
b.setBank("LiSi",999);
}
else
{
b.setBank("ZhangSan",100);
}