你没有调用run()方法,只是将ABC实例化,程序运行过程中并未改变10赋值给i,所以还是把1返回!

解决方案 »

  1.   

    线程并没有马上将10赋给i
    请看
    class ABC implements Runnable
    {
    public int i=1;
    public void run()
    {
    this.i=10;
    }
    } class Dominic
    {
    public static void main(String args[])
    {
    ABC a=new ABC();
    new Thread(a).start();
    while(a.i==1)
    ; System.out.println(a.i);
    }
    }
    输出为10
      

  2.   

    new Thread(a).start();
    可能是这步上导致的你的线程没有启动
    试试这样:
    public class Dominic
    {
    public static void main(String args[])
    {
                      ABC a=new ABC();
                      Thread mythread=new Thread(a);
                      mythread.start();
    int j=a.i;
    System.out.println(j);
    }
    }
      

  3.   

    这是因为在new Thread(a).start();之后,并没有马上开始这个线程,而是继续在执行主线程。如果加上join(),则可使输出为10:
    class ABC implements Runnable
    {
    public int i=1;
    public void run()
    {
                    this.i=10;
             }
    }public class Dominic
    {
    public static void main(String args[])
    {
           ABC a=new ABC();
                    Thread t = new Thread(a);
                    t.start();
                    try{
                    t.join();
                    }
                    catch(Exception e) {
                    e.printStackTrace();
                    }
                    int j=a.i;
                    System.out.println(j);
    }
    }
      

  4.   

    to ispring:
    不行,程序进入死循环,意味着没有a.i=100出现。
      

  5.   

    我认为是线程的启动时间的原因,当我在JB里用调试模式时,因为是step over所以执行到j=a.i时j已经变为10了.当然最后的输出也是10
      

  6.   

    to ispring:
    我在1.2上编译运行了十分钟,还没有出结果。to namowen:
    可以。
      

  7.   

    这是个考试选择题,
    A 1
    B 10
    C the value of j cannot be determined
    D An error cause compilation to fail到底选哪个呢???
      

  8.   

    程序运行到start()处 便继续执行 等于有两个可运行态的线程
    我觉得j应该不确定
      

  9.   

    ispring 的不行,lanyunfeng的可以,核心思想就是让出当前main线程的时间片。
    ...
    ABC a=new ABC();
    new Thread(a).start();
    Thread.yield();
    int j=a.i;
    System.out.println(j);
    ...
    好像也可以的吧,但lanyunfeng 的好一些,保证得到10
      

  10.   

    to lanyunfeng
    ABC a=new ABC();
    Thread mythread=new Thread(a);
    mythread.start();

    ABC a=new ABC();
    new Thread(a).start();
    有什么区别?
      

  11.   

    一个线程初始化的时间比int j=a.i;System.out.println(j);这样的代码
    耗费时间要长得多!
    其实这里现成还没运行到int j=a.i;这句,你让主线程SLEEP几个毫秒看看,结果就会不一样!
      

  12.   

    SJCP的题目就是TMD烂!这个题我觉得是模棱两可,如果从线程的耗费时间上来考虑的话,就脱离了Java的初衷了。别忘了,这个还是跟你的操作系统有关的。
      

  13.   

    这是个考试选择题,
    A 1
    B 10
    C the value of j cannot be determined
    D An error cause compilation to fail到底选哪个呢???选 C
      

  14.   

    把你的EMILtell me.
    qq117637