JAVA 语言程序设计》期末考试一试题及答案
一、选择题
1.请说出以下代码的履行结果 : String s = "abcd";
if (s = = s1) System.out.println("the same");
if (s.equals(s1)) System.out.println("equals");
A. the same    equals    B. equals
C. the same    D. 什么结果都不输出
2.以下相关 Java中接口的说法哪个是正确的?
A.接口中含有详细方法的实现代码
B.若一个类要实现一个接口,则用到    implements关”键字
C.若一个类要实现一个接口,则用到  extends重点”字
D.接口不同意继承
3.以下代码的履行结果是什么?
String s1 = "aaa";
s1.concat("bbb");
System.out.println(s1);
A.The string "aaa".
B.The string "aaabbb".
C.The string "bbbaaa".
D.The string "bbb".
4. 假如有一个对象 myListener ( 此中 myListener 对象实现了 ActionListener 接口 ), 以下哪条语句使得 myListener 对象可以接受办理来自于 smallButton 按钮对象的动作事件 ?
A.smallButton.add(myListener);
B.smallButton.addListener(myListener);
C.smallButton.addActionListener(myListener);
D.smallButton.addItem(myListener);

二.读程序题
1.java程序设计考试题读以下代码,说出这段程序的功能。
import java.io.*;
public class Test{
public static void main( String [] argv) {
try {
BufferedReader is =
new BufferedReader( new InputStreamReader(System.in)); String inputLine;
While ((inputLine = is.readLine ())!= null) {
System.out.println(inputLine);
}
is.close();
}catch (IOException e) {
System.out.println("IOException: " + e);
}
}
}
答案:读取键盘输入,显示到屏幕上,直到键盘输入为空为止。
2、 读以下程序,写出正确的运转结果。
class test {
public static void main (String [] args ){
int x=9, y;
if (x>=0)
if (x>0)
y=1;
else y=0;
else y=-1;
System.out.println(y);
}

}
答案: 1
3、 读程序,写出正确的运转结果。
public class Father{
int a=100;
public void miner(){
a--;
}
public static void main(String[] args){
Father x = new Father();
Son y = new Son();
System.out.println(y.a);
System.out.println( y.getA());
y.miner();
System.out.println(y.a);
System.out.A());
}
}
class Sonextends Father{
int a = 0;
public void plus(){
a++;
}
public int getA() {
return super.a;
}
}
答案:
0

100

0
99
.简答题
1.Java语言的特。答:
简单性: Java风格近似于 C++ ,但它摒弃了 C++中简单惹出发序错误的地方
面向对象: Java语言的设计是完整面向对象散布式:
解说履行:
强健性: Java供给自动垃圾回收体制,异样办理体制,进行严格的种类检查平台没关性:
安全性
多线程
动向性
2.请描绘 AWT 事件模型。
答:
联合 AWT 事件模型并举例来说:
import java.awt.event.*;
1.监听对象一定实现对应事件的接口
class MyFirstFrame extends Frame implements ActionListener
{...}
2.明确事件的接口形式
public void actionPerformed ( ActionEvent event) {    }
3.MyFirstFrame 类一定实现接口 ActionListener 中的全部方法。
4.注册监听对象 .
为了把 MyFirstFrame对象注册为两个按钮的事件监听对象,一定在 MyFirstFrame 的结构函数中增添语句以下:
cancelButton.addActionListener(this);
okButton.addActionListener(this);