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

java程序设计期末考试试题 (1)

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

百度文库 - 让每个人平等地提升自我!

}

public class InheritAbstract extends SubAbstract{ }

在以上这段程序中:

抽象类有:SuperAbstract和 (1) (写出类名) 非抽象类有: (2) (写出类名) 接口有: (3) (写出接口名)

AsSuper中的x()方法是(4)方法,所以在InheritAbstract中必须对它进行(5) 答案:

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

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

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

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

void print() {

i++;

return (1) ;//将当前对象的地址作为返回值返回 public void x(){…} public int c(int i ) {…} public String f(){…}

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

InheritAbstract instance=new InheritAbstract(); instance.x(); instance.a(); instance.b(); instance.c(100);

System.out.println(instance.f());

6

百度文库 - 让每个人平等地提升自我!

}

}

System.out.println(\

public static void main(String args[]){

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

}//多次调用方法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流

7

百度文库 - 让每个人平等地提升自我!

} } 答案:

(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();

8

百度文库 - 让每个人平等地提升自我!

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

9

java程序设计期末考试试题 (1)

百度文库-让每个人平等地提升自我!}publicclassInheritAbstractextendsSubAbstract{}在以上这段程序中:抽象类有:SuperAbstract和(1)(写出类名)非抽象类有:(2)(写出类名)接口有:
推荐度:
点击下载文档文档为doc格式
3f63e2ir752mdyx423a46cyp27lzc201br8
领取福利

微信扫码领取福利

微信扫码分享