CodeMartain 2021-10-08 10:35 采纳率: 76.3%
浏览 34
已结题

这个代码的运行结果有人给解释一下吗?最好是带图的那种;

这个代码的运行结果有人给解释一下吗?

import java.util.Arrays;
public class VisibilityDemo {
   volatile static  int []array=new int[2];
    private static class Tests{
        public  void methodA(){
           array[0]=100;
           array[1]=200;
            System.out.println(Arrays.toString(array));
        }
    }
    public static void main(String[] args) {
        Tests tests= new Tests();
        Thread thread = new Thread(() -> {
         tests.methodA();
        });
      
       array[0]=888;
       array[1]=999;
        thread.start();
    }
}

能解释一下这个程序怎么运行出结果的吗?

  • 写回答

2条回答 默认 最新

  • limit、T 2021-10-08 10:59
    关注

    img

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月21日
  • 创建了问题 10月8日