好文档 - 专业文书写作范文服务资料分享网站

《JAVA语言程序设计》期末考试试题及答案7(应考必备题库)

天下 分享 时间: 加入收藏 我要投稿 点赞

《JAVA语言程序设计》期末考试试题及答案7(应考必备题库)

一、选择题

1. 请说出下列代码的执行结果 : String s = \

String s1 = new String(s);

if (s = = s1) System.out.println(\if (s.equals(s1)) System.out.println(\A. the same equals

B. equals

C. the same

D. 什么结果都不输出

2. 下列有关 Java 中接口的说法哪个是正确的? A. 接口中含有具体方法的实现代码

B. 若一个类要实现一个接口,则用到 “implements” 关键字 C. 若一个类要实现一个接口,则用到“ extends ”关键字 D. 接口不允许继承

3. 下列代码的执行结果是什么? String s1 = \s1.concat(\System.out.println(s1); A. The string \B. The string \C. The string \D. The string \

4. 如果有一个对象 myListener ( 其中 myListener 对象实现了 ActionListener 接口 ), 语句使得 myListener 对象能够接受处理来自于 smallButton 按钮对象的动作事件 ? A. smallButton.add(myListener); B. smallButton.addListener(myListener); C. smallButton.addActionListener(myListener); D. smallButton.addItem(myListener);

二.读程序题

1. 读下列代码,说出这段程序的功能。 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(\} } }

答案:读取键盘输入,显示到屏幕上,直到键盘输入为空为止。

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.println(y.getA()); }

}

class Son extends 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);

3. 在 Java中,怎样创建一个线程? 答:

1、定义类来实现Runnable接口

class TestThread implements Runnable { public void run() { …} } 2、继承Thread类来实现

class TestThread extends Thread { TestThread(String name) { super(name); start(); }

public void run() {…} }

《JAVA语言程序设计》期末考试试题及答案7(应考必备题库)

《JAVA语言程序设计》期末考试试题及答案7(应考必备题库)一、选择题1.请说出下列代码的执行结果:Strings=\Strings1=newString(s);if(s==s1)System.out.println(\if(s.equals(s1))System.out.println(\A
推荐度:
点击下载文档文档为doc格式
3lors0mdbx7u3cm9b9nu86wqu5roq7003c0
领取福利

微信扫码领取福利

微信扫码分享