What will happen when you attempt to compile and run the following code?public class MyThread extends Thread
{
public static void main(String argv[])
{
        MyThread mt = new MyThread();
         mt.run();
        }        public void start()
{
         for (int i = 0; i <10; i++)
{
                 System.out.println("Value of i = " + i);
                }
        }
}解答:
D is correct. If you look carefully, in the above code the run() method is invoked on Thread class. To start a Thread, the start() method is called which in turn invokes the run() method. The run method of Thread class does nothing. Thus nothing will be printed out. Thus C is incorrect. A is incorrect as there is a run method in the Thread class. B is incorrect as there will not be any run time error on running the above code.

解决方案 »

  1.   

    D是正确的。如果你仔细看看,在上面的代码run ( )方法是引用线程类。启动一个线程,一开始( )方法被调用,从而调用run ( )方法。 run方法中的线程类没有任何作用。因此,没有什么会印出来。因此, C是不正确。 A是不正确这里存在一个run方法,在线程类。 B是不正确作为将不会有任何运行时间误差对运行上面的代码。
      

  2.   

    这哪里 有RUN()方法啊 ? 晕
      

  3.   

    楼主你咋会有那么多的分?准备考SCJP吧,呵呵
      

  4.   

    在你试图编译和运行下面代码时会发生什么?public class MyThread extends Thread
    {
        public static void main(String argv[])
        {
                MyThread mt = new MyThread();
                mt.run();
            }        public void start()
        {
                for (int i = 0; i <10; i++)
            {
                        System.out.println("Value of i = " + i);
                    }
            }
    }D正确,如果你仔细看,在上述代码中run()方法被Thread类执行。开始一个线程,当run()被执行时start()方法被调用。Thread类中的run()方法什么事都没做。所以没用东西会被打印出来。故C不正确。A错误因为Thread类中有run()方法。B错误因为运行时不会有任何错误出现。
      

  5.   

    回2楼:
    mt.run();
    在这句调用了run方法...这题是考验你对线程的掌握了...
      

  6.   

    呵呵 是啊SCJP貌似也不容易啊  我做来做去也就50%准确率 还有好多知识点没理解呢。