public class Test {
  public static void main(String[] args){
    Test1 s;
    try
    {
     s = new Test1();
    }
    catch(Exception e)
    {
     System.out.println("*********");
    }
    if( s == null )
      System.out.println("******s is null");
    else
      System.out.println("*******s is not null"); 
  } 
}

解决方案 »

  1.   

    按照你的修改,新的错误信息如下 :
    Test.java:19: variable s might not have been initialized
        if( s == null )
            ^
    1 error
      

  2.   

    对了!函数变量是不会自动初始化的。改为
    public class Test {
      public static void main(String[] args){
        Test1 s=null;
        try
        {
         s = new Test1();
        }
        catch(Exception e)
        {
         System.out.println("*********");
        }
        if( s == null )
          System.out.println("******s is null");
        else
          System.out.println("*******s is not null"); 
      } 
    }