本帖最后由 余松霖 于 2011-12-17 19:54 编辑
- class Res
- {
- String name;
- String sex;
- }
- class Input implements Runnable
- {
- private Res r;
- Input(Res r)
- {
- this.r=r;
- }
- private void run()
- {
- int x=0;
- while(true)
- {
- if (x==0)
- {
- r.name="男人";
- r.sex="是男人";
- }
- else
- {
- r.name="女人";
- r.sex="是女人";
- }
- x=x++%2;
- }
- }
- }
- class Output implements Runnable
- {
- private Res r;
- Output(Res r)
- {
- this.r=r;
- }
- public void run()
- {
- while (true)
- {
- System.out.println(r.name+".."+r.sex);
- }
- }
- }
- class InOutDemo
- {
- public static void main(String[] args)
- {
- Res r=new Res;
-
- Input i=new Input(r);//这里错了吗
- Output o=new Output(r);
- Thread t1=new Thread(i);
- Thread t2=new Thread(o);
- t1.start();
- t2.start();
- }
- }
复制代码 InOutDemo.java:57: 错误: 需要'('或'['
Input i=new Input(r);
^
1 个错误
|