分析以下代码。
public static void test(string ConnectString)
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = ConnectString;
try
{
conn.Open();
…….
}catch(Exception Ex)
{
MessageBox.Show(Ex.ToString());
}finally
{
if (!conn.State.Equals(ConnectionState.Closed))
conn.Close();
}
请问
1)以上代码可以正确使用连接池吗?
2)以上代码所使用的异常处理方法,是否所有在test方法内的异常都可以被捕捉并显示出来?
第1题:
编写类 String 的构造函数、析构函数和赋值函数
已知类 String的原型为:
class String
{
public:
String(const char *str = NULL); // 普通构造函数
String(const String &other); // 拷贝构造函数
~ String(void); // 析构函数
String & perate =(const String &other); // 赋值函数
private:
char *m_data; // 用于保存字符串
};
请编写 String的上述 4 个函数。
第2题:
第3题:
给定以下代码,以下哪句是正确的? public class Test { String s; static class Inner { void testMethod() { s = "Hello world."; } } public static void main(String[] argv) { Inner i = new Inner(); i.testMethod(); System.out.println(s); } }
A.编译通过,但是运行时刻出错,因为s没有被初始化
B.无法编译,因为Test类里的String s不是static的
C.编译通过,打印出Hello world.
D.无法编译,因为Inner不能像这样在main中使用
第4题:
第5题:
已知类Test中的方法method以通过Test.method方式进行操作,则method应是()。
A.static方法
B.重载方法
C.void方法
D.构造方法