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

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

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

(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(应考必备题库)

(2)InheritAbstract;(3)AsSuper;(4)抽象;(5)覆盖和实现。3.按注释完成程序publicclassLeaf{}输出结果为i=(3)答案:(1)this;(2)newLeaf();(3)34.按注释提示完成文件复制的程序
推荐度:
点击下载文档文档为doc格式
5cv1r5prmh1cf865breu5a66i6tmib010xf
领取福利

微信扫码领取福利

微信扫码分享