教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 综合文档 >

《JAVA语言程序设计》期末考试试题及答案(9)

来源:网络收集 时间:2026-08-20
导读: } } void print() { } public static void main(String args[]){ Leaf x = (2); //创建Leaf类的对象x x.increment().increment().increment().print(); System.out.println(\ }//多次调用方法increment(),返回的都

}

}

void print() { }

public static void main(String args[]){

Leaf x = (2); //创建Leaf类的对象x x.increment().increment().increment().print(); System.out.println(\

}//多次调用方法increment(),返回的都是x的地址,i 值表示调用次数

输出结果为 i = (3) 答案: (1) this; (2) new Leaf(); (3) 3

4. 按注释提示完成文件复制的程序 //FileStream源代码如下: import java.io.*; class FileStream {

public static void main(String args []) {

try {

File inFile = new File(\//指定源文件 File outFile = new File(\指定目标文件 FileInputStream fis =(1);

FileOutputStream fos = new FileOutputStream(outFile);

int c;

while ((c = fis.read ())!=-1)

(2);

fis.close();

fos.close(); }

catch (Exception e) {

System.out.println(\

//逐字节从源文件中输入,再输出到fos流

}

}

} 答案:

(1) new FileInputStream(inFile); (2) fos.write(c);

5. 阅读程序,给出结果:

// AbstractClassDemo.java源代码如下:

abstract class Shape { //定义抽象类Shape和抽象方法display }

class Circle extends Shape { }

class Rectangle extends Shape { }

class Triangle extends Shape { }

public class AbstractClassDemo{ }

public static void main(String args[]){ }

(new Circle()).display(); //定义无名对象来调用对应的display方法 (new Rectangle()).display(); (new Triangle()).display(); void display() { }

//实现抽象类的方法

System.out.println(\void display() { //实现抽象类的方法

System.out.println(\}

void display() { }

//实现抽象类的方法

System.out.println(\abstract void display();

输出结果是 ?

答案:(1) Circle; (2) Rectangle; (3) Triangle。

《JAVA程序设计》期末考试试题 (七)

一、选择题

1. 请说出下列代码的执行结果 : String s = \ B String s1 = new String(s);

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

2. 下列有关 Java 中接口的说法哪个是正确的? B 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 按钮对象的动作事件 ? C A. smallButton.add(myListener); B. smallButton.addListener(myListener); C. smallButton.addActionListener(myListener); D. smallButton.addItem(myListener);

B. equals D. 什么结果都不输出

二.读程序题

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语言的特点。

…… 此处隐藏:1137字,全部文档内容请下载后查看。喜欢就下载吧 ……
《JAVA语言程序设计》期末考试试题及答案(9).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/404153.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)