2024年3月21日发(作者:)

1.下面能够得到文件“”的父路径的是:

A。String name= entName(“file。txt”);

B。String name= (new File(“”))。getParent();

C。String name = (new File(“file。txt”))。getParentName();

D。String name= (new File(“"))。getParentFile();

2。在Java中,要创建一个新目录,要使用的类的实例是:

B。FileOutputStrean

riter

D。Dir

3。题目代码的功能为:在d:创建一个文件“test。txt”,并向文件写入

“HelloWorld”,然后删除文件。

public static void main(String[] args) {

File file = new File("d:", ”");

try {

<填入代码>

} catch (Exception e) {

tackTrace();

A. BufferedWriter bw = new BufferedWriter(new FileWriter(file));

bw。write("HelloWorld”);

bw。close();

if (()) {

file。delete();

B。 BufferedWriter bw = new BufferedWriter(new FileWriter(file));

bw。write("HelloWorld");

bw。close();

if (file。exists()) {

File();

edWriter bw = new BufferedWriter(file);

bw。write("HelloWorld”);

();

if (()) {

file。delete();

D。 BufferedWriter bw = new BufferedWriter(file);

bw。write("HelloWorld");

bw。close();

if (()) {

file。deleteFile();

4。题目代码功能为:打印扩展名为txt的文件

public static void main(String[] args){

String dir=”d:/javalesson";

File currDir=new File(dir);

FilenameFilter filter=new JavaFilter();

String[] javaFiles=(filter);

for(int i=0;i

n(javaFiles[i]);

代码中JavaFilter类的代码为:

A。public class JavaFilter implements FilenameFilter

public void accept(File dir, String name) {

return th(".txt”);

class JavaFilter implements FilenameFilter {

public boolean accept(File dir, String name) {

return name。endsWith("。txt”);

class JavaFilter extends FilenameFilter {

public boolean accept(File dir, String name) {

return name。endsWith("。txt”);

}

D。 public class JavaFilter extends FilenameFilter {

public void accept(File dir, String name) {

return name。endsWith("。txt");

}

5。 下列关于序列化和反序列化描述正确的是

A.序列化是将数据转换为 n个byte序列的过程

B.反序列化是将n个 byte 转换为一个数据的过程

C。将类型int 转换为4 byte是反序列化过程

D。将8个字节转换为long类型的数据是序列化过程

6。请看下列代码:

interface Foo {

class Alpha implements Foo {

class Beta extends Alpha {

}

public class Delta extends Beta {

public static void main(String[] args) {

Beta x = new Beta();

〈插入代码〉

}

在<插入代码〉处,填入下列代码,运行时能引起java。astException异

常的是:

A。 Alpha a = x;

B。 Foo f= (Delta)x;

C。 Foo f= (Alpha)x;

D。 Beta b = (Beta)(Alpha)x;

7.请看下列代码:

1:public class Foo {

2: public static void main(String[] args) {

3: try {

4: A a = new A();

5: 1();

6: } catch (Exception e) {

7: (”an error occurred");

8: }

9: }

10:}

1:class A {

2: public void method1() {

3: B b = new B();

4: b。method2();

5: 。println(”method one");

6: }

7:}

1:class B {

2: public void method2() {

3: C c = new C();

4: c。method3();

5: System。out。println("method two”);

6: }

7:}

1:class C {

2: public void method3() {

3: System。out。println("method three");

4: throw new NullPointerException();

5: }

6:}

关于上述代码说法正确的是:

A。Foo类的第7行将被执行

B。A类的第5行将被执行

C。B类的第5行将被执行

D。C类的第3行将被执行

8。请看下列代码:

public class A {

public String sayHello(String name) throws TestException {

if (name == null) {

throw new TestException();

return "Hello” + name;

public static void main(String[] args) throws TestException {

A a=new A();

System。out。println(lo(null));

class TestException extends Exception {

关于上述代码说法正确的是:

A.A类编译失败

B.代码”。println(a。sayHello(”John"));”行,会抛出未检查异常

TestException

C。代码” A a=new A();"行,会抛出未检查异常TestException

D。代码"System。n(a。sayHello(”John”));”行,会抛出已检查异常

TestException

9。请看下列代码:

1. // some code here

2。 try {

3。 // some code here

4。 } catch (SomeException se) {

5。 // some code here

6. } finally {

7. // some code here

8. }

下面哪三种情况能使第7行的代码执行:

A.第3行抛出异常

B.第1行抛出异常

C.第5行抛出异常

D.第3行代码成功执行

10。以下说法错误的是:

… catch .. catch,多个catch时,后一个catch捕获类型一定是前一个的父类

….finally 可以组合使用

C。throw抛出一些异常,程序不进行处理,程序编译也无错误

一定是写在方法后面

11。下列代码运行的结果是:

public class A {

public void process() {

System。(”A ");

public static void main(String[] args) {

try {

((A) new B()).process();

} catch (Exception e) {

System。(”Exception”);

}

class B extends A {

public void process() throws RuntimeException {

s();

if (true)

throw new RuntimeException();