日期:2014-05-20  浏览次数:20658 次

三个题目,帮忙具体解释一下


1.What’s   the   difference   between   A   and   B?

 

A.

class   Test

{

public   void   test()

{

        synchronized(this)

        {

                ...

        }

}

}

  B.

class   Test

{

      public   synchronized   void   test()

      {

              ...  

      }

 

}
 

 

2.           Why   the   init()   method   must   be   private?   Please   provide   an   example   to   explain   it.

 

class   Test

{

public   Test()

{

      init();

}

 

private   void   init()

{

      …

}

}

 

3.           Find   problems   in   this   code   snippet:

 

class   Test

{

public   static   void   executeQuery(   String   connectionName,     String   statementText)   throws   SQLException

{

        Connection   connection   =   null;

        try  

{

        //Get   a   connection   from   connection   pool

                connection   =   manager.getConnection(connectionName);

                Statement   statement   =   connection.createStatement();

                ResultSet   resultSet   =  

                                    statement.executeQuery(statementText);

                for   (int   i   =   0;   resultSet.next();   i++)  

                {

                        ...

                }

 

                resultSet.close();

                statement.close();

 

                return   ;

        }

        catch   (SQLException   e)  

        {

                throw(new   SQLException(statementText));

        }

}

}


------解决方案--------------------