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);
}
}
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);
}
}
解决方案 »
- 求一套讲的好的JAVA基础的视频和书,谁的比较好。还有编译工具。
- tcp传输的速率问题?
- 求助问题:程序必须最小化才能显示正确的界面
- 关于Java泛型在DAO中的应用问题
- 能提供一个输入输出字符串的简单程序吗?谢谢~~
- Java中调用记事本的问题,请各位帮我看看。
- 一个不错的java书籍下载网站,不敢独享
- 招聘
- 一个菜鸟问题!!!!
- WIN8_64+JNA+Eclipse,自己的DLL无法调用???在线等!!!
- 急!请问如何传输整个文件夹里的东西?(包括子文件夹里的文件)
- 救命啊!Exception in thread "main" java.lang.NoClassDefFoundError
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();
}
}
==============================================
对不住啊,错误是不少,都一一改正了.