public class Test {

public static void main(String[] args)
{
new Test();
System.out.print("Done");
}

public Test()
{
Test t1 = this;
Test t2 = this;

synchronized(t1)
{
try
{
t2.wait();
}
catch(InterruptedException e)
{
System.out.print("!");
}
catch(Exception e)
{
System.out.print("!!");
}
finally
{
System.out.print("@@");
}
}

System.out.print("!!!");
}}
请问以上代码运行后,输出结果是什么?
谢谢了~!

解决方案 »

  1.   

    什么都不输出,执行到t2.wait()就停下来了!wait()方法中扔出了InterruptedException异常:
        public final void wait() throws InterruptedException {
    wait(0);
        }
      

  2.   

    不同步的话会打印出:!!@@!!!Done,说明catch到了Exception异常!
      

  3.   

    那请问那个t1同步是什么含义呢?这个t2.wait()会对t1有影响吗?还有下面对中断异常的捕获,究竟是怎么件事情啊
      

  4.   

    是什么interrupt了t2了呢?
    学习
      

  5.   

    Test t1 = this;
    Test t2 = this;
    这两句到底要作什么啊?
      

  6.   

    因为所有的动作,在当执行到t2.wait()时,处于等待状态。因此,后面的程序代码就执行不下去了啊!包括:
    finally
    {
    System.out.print("@@");
    }
    }System.out.print("!!!");
    }
    这些都需要等t2.wait()执行完后才会继续。而main函数里面的System.out.print("Done");则更不会执行,因为new Test();这个动作还停在t2.wait()呢,所以,什么输出结果都不会有!