1、[单选题]在编写访问数据库的 Java 程序时,Connection 对象的作用是( )
A、存储查询结果
B、在指定的连接中处理 SQL 语句
C、用来表示与数据库的连接
D、用来创建数据库的连接
2、[填空题]注册鼠标点击事件监视器的方法是___________。
3、[主观题]【程序分析题】阅读下列程序,请写出该程序的功能。
import java.io.*; import java.awt.*; import javax.swing.*; import java.awt.event.*;
class MyWindow extends JFrame implements ActionListener{
JTextArea text;BufferedReader in;JTextField fileName; FileReader file;
MyWindow(){
Container con=this.getContentPane();//获得内容面板
con.setLayout(new BorderLayout());
fileName=new JTextField("输入文件名"); fileName.addActionListener(this); text=new JTextArea(20,30); JScrollPane jsp:new JScrollPane(text); con.add(jsp,BorderLayout.CENTER);
con.add(fileName,"South");setVisible(true);
}
public void actionPerformed(ActionEvent e)
{ String s; try{File f=new File(fileName.getText()); file=new FileReader(f); in=new BufferedReader(file); } catch(FileNotFoundException el){} try{ while((s=in.readLine())!=null) text.append(s+'\n');
}catch(IOException exp){}
}
}
public class Test34{ public static void main(String args[ ]) {new MyWindow();}
}
4、[主观题]【程序分析题】阅读下列程序,请写出该程序的输出结果。
class MyThread extends Thread {
String message; int s;
MyThread(String message, int sec) { this.message = message; s = sec; }
public void run( ) {
try{ sleep(s); }catch(InterruptedException e){}
System.out.println(message+" "+getPriority( ));
}
}
class ThreadTest {
public static void main(String args[]){
Thread foo = new MyThread("Foo", 1000);
foo.setPriority(Thread.MIN_PRIORITY); foo.start( );
Thread bar = new MyThread("Bar",800);
bar.setPriority(3); bar.start( );
Thread gar = new MyThread("Gar",400);
gar.setPriority(7); gar.start( );
Thread kar = new MyThread("Kar", 100);
kar.setPriority(Thread. MAX_PRIORITY); kar.start( );
}
)
注:假设处理机中没有其它线程占用资源。
5、[主观题]【程序分析题】阅读下列程序,请写出该程序的输出结果。
class Test32a {
String name; int age; long number;
Test32a(long number, String name,int age) {
System.out.println("Name: "+name);
System. out. println("Age: "+age);
System.out.println("Tel: " +number);
}
}
class Test32b extends Test32a {
Test32b(long number, String name,int age,boolean b) {
super(number, name,age); System.out.println("Married: "+b);
}
}
public class Test32 {
public static void main(String args[]) {
Test32b abe=new Test32b(4747,"Tony",29,true);
}
}