本帖最后由 枫儿 于 2013-10-10 15:38 编辑
为什么都提示找不到函数?是代码哪的问题?
- class rec
- {
- String name;
- String age;
- }
- class Input implements Runnable
- {
- private rec r;
- Input(rec r)
- {
- this.r=r;
- }
- public void run()
- {
- int x=0;
- while (true)
- {
- synchronized(r)
- {
- if(x==0)
- {
- r.name="make";
- r.age="Man";
- }
- else
- {
- r.name="扣扣";
- r.age="女女女";
- }
- x=(x+1)%2;
-
- }
- }
- }
- }
- class out implements Runnable
- {
- private rec r;
- out(rec r)
- {
- this.r=r;
- }
- public void run()
- {
- while (true)
- {
- synchronized(r)
- {
- System.out.println(r.name+"...."+r.age);
- }
- }
- }
- }
- class dxctx
- {
- public static void main(String[] args)
- {
- rec r=new rec();
- Input in=new Input();
- out o=new out();
- Thread t1=new Thread(r);
- Thread t2=new Thread(r);
- t1.start();
- t2.start();
- }
- }
复制代码 |