第一范文网 - 专业文章范例文档资料分享平台

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

来源:用户分享 时间:2025/7/27 21:47:57 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

(2) InheritAbstract; (3) AsSuper; (4) 抽象; (5) 覆盖和实现。

3. 按注释完成程序 public class Leaf { }

输出结果为 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(\ FileInputStream fis =(1);

FileOutputStream fos = new FileOutputStream(outFile);

int c;

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

private int i = 0; //此属性值用于检验

Leaf increment(){ //定义方法increment(),返回值是Leaf类的对象 }

void print() { }

public static void main(String args[]){

Leaf x = (2); //创建Leaf类的对象x

x.increment().increment().increment().print(); System.out.println(\

i++;

return (1) ;//将当前对象的地址作为返回值返回

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

File outFile = new File(\//指定目标文件

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

(2);

fis.close();

fos.close(); }

catch (Exception e) {

} 答案:

(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(); void display() { }

//实现抽象类的方法

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

System.out.println(\}

void display() { }

//实现抽象类的方法

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

System.out.println(\}

}

}

(new Triangle()).display();

输出结果是 ?

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

《JAVA语言程序设计》期末考试试题及答案6(应考必备题库).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c5cv1r5prmh1cf865breu5a66i6tmib010xf_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top