public class A{
  public int[] arrays=new int[10];
  public synchronized void method1(int i,int off){
    arrays[off]=i;
  }
  public int method2(int i){
    return arrays[i];
  }
  public static void main(String[] args) {
    A a=new A();
    a.method1(10,0);
    B b=new B();
    C c=new C();
  }
}public class B implements Runnable{
  public A a=null;
  public int i,off;
  public B(A arg,int i,int off){
    a=arg;
    this.i=i;
    this.off=off;
    new Thread(this).start();
  }
  public void run(){
     a.method2(i,off);
  }
}public class C implements Runnable{
  public A a=null;
  public B(A arg){
    a=arg;
    new Thread(this).start();
  }
  public void run(){
    System.out.println(a.method2(0));
    a.method1(0,0);
  }
}

解决方案 »

  1.   

    public class A{
      public int[] arrays=new int[10];
      public synchronized void method1(int i,int off){
        arrays[off]=i;
      }
      public int method2(int i){
        return arrays[i];
      }
      public void output(){
       for(int j=0;j<10;j++)
         System.out.println("arrays["+j+"]="+arrays[j]);
      }
      public static void main(String[] args) {
        A a=new A();
        a.method1(10,0);
        a.output();
        B b=new B(a,10,5);
        C c=new C(a);
      }
    }
    public class B implements Runnable{
      public A a=null;
      public int i,off;
      public B(A arg,int i,int off){
        a=arg;
        this.i=i;
        this.off=off;
        new Thread(this).start();
      }
      public void run(){
         a.method1(i,off);
         System.out.println("线程B:");
         a.output();
      }
    }
    public class C implements Runnable{
      public A a=null;
      public C(A arg){
        a=arg;
        new Thread(this).start();
      }
      public void run(){
       System.out.println("线程C:");
       System.out.println("C读取arrays数组的第一个元素值为:"+a.method2(0));
        a.method1(0,0);
        a.output();
      }
    }
    ==============================================
    对不住啊,错误是不少,都一一改正了.