SCJP Mock Exam 1(8)
添加时间: 2007-9-23 2:40:14 作者: JAVA题库 阅读次数:74 来源: http://www.d9soft.com
1) FileOutputStream has no constructors matching the given arguments.
2) An IOExeception will be thrown if a file named "data" already exists.
3) An IOExeception will be thrown if a file named "data" does not already exist.
4) If a file named "data" exists, its contents will be reset and overwritten.
5) If a file named "data" exists, output will be appended to its current contents.
Q60
Given the following code, write a line of code that, when inserted at the indicated location, will make the overriding method in Extension invoke the overridden method in class Base on the current object.
class Base {
public void print() {
System.out.println("base");
}
}
class Extention extends Base {
public void print() {
System.out.println("extension");
// insert line of implementation here
}
}
public class Q294d {
public static void main(String args[]) {
Extention ext = new Extention();
ext.print();
}
}
Fill in a single line of implementation.
Q61
Given that file is a reference to a File object that represents a directory, which code fragments will succeed in obtaining a list of the entries in the directory?
1) Vector filelist = ((Directory) file).getList();
2) String[] filelist = file.directory();
3) Enumeration filelist = file.contents();
4) String[] filelist = file.list();
5) Vector filelist = (new Directory(file)).files();
Q62
What will be written to the standard output when the following program is run?
public class Q03e4 {
public static void main(String args[]) {
String space = " ";
String composite = space + "hello" + space + space;
composite.concat("world");
String trimmed = composite.trim();
System.out.println(trimmed.length());
}
}
1) 5
2) 6
3) 7
4) 12
5) 13
Q63
Given the following code, which statements concerning the objects referenced through the member variables i, j and k are true, given that any thread may call the methods a, b and c at any time?
class Counter {
int v = 0;
synchronized void inc() { v++; }
synchronized void dec() { v--; }
}
public class Q7ed5 {
Counter i;
Counter j;
Counter k;
public synchronized void a() {
i.inc();
System.out.println("a");
i.dec();
}
public synchronized void b() {
i.inc(); j.inc(); k.inc();
System.out.println("b");
i.dec(); j.dec(); k.dec();
}
public void c() {
k.inc();
System.out.println("c");
k.dec();
}
}
1) i.v is guaranteed always to be 0 or 1.
2) j.v is guaranteed always to be 0 or 1.
3) k.v is guaranteed always to be 0 or 1
4) j.v will always be greater than or equal to k.v at any give time.
5) k.v will always be greater than or equal to j.v at any give time.
Q64
Which statements concerning casting and conversion are true?
1) Conversion from int to long does not need a cast.
2) Conversion from byte to short does not need a cast.
3) Conversion from float to long does not need a cast.
4) Conversion from short to char does not need a cast.
5) Conversion from boolean to int using a cast is not possible.
Q65
Given the following code, which method declarations, when inserted at the indicated position, will not cause the program to fail compilation?
public class Qdd1f {
public long sum(long a, long b) { return a + b; }
// insert new method declaration here
}
1) public int sum(int a, int b) { return a + b; }
2) public int sum(long a, long b) { return 0; }
3) abstract int sum();
4) private long sum(long a, long b) { return a + b; }
5) public long sum(long a, int b) { return a + b; }
Q66
The 8859-1 character code for the uppercase letter A is 65. Which of these code fragments declare and initialize a variable of type char with this value?
1) char ch = 65;
2) char ch = '65';
3) char ch = '041';
4) char ch = 'A';
5)char ch = "A";
1) 4
2) 2
3) 2
4) 2, 6
5) 4
6) 3
7) 4
8) 4
9) 1, 2, 3, 5
10) 1, 5
11) 4
12) 5
13) 1
14) "LayoutManager layout = new GridLayout(2, 3);"
or: "LayoutManager layout = new GridLayout(2, 3)"
15) 5
16) 3
17) 2, 4
18) 4, 5
19) 2
20) 4
21) 4
22) 5
23) 1, 2
24) 2
25) 1, 4
26) 3
27) 4
28) 3 (? no run-time exception)
29) 1, 4, 5
30) 5
31) 2, 5
32) 1
33) 3, 4
34) 2, 3
35) 2, 4
36) 3, 5
37) 2, 5
38) 3, 4
39) 1
40) 1, 2, 3
41) "wait"
42) 3
43) 3
44) 5
45) 4
46) 1, 2, 3, 4
47) 2
48) 1, 2, 4
49) 1
50) 2, 3
51) 1, 5
52) 1, 3
53) 1
54) 2, 5
55) 5
56) 2, 3
57) 4
58) 2, 3
59) 5
60) super.print();
61) 4
62) 1
63) 1,2
64) 1,2,5
65) 1,5
66) 1,4
上一篇文章: SCJP Mock Exam 1(7) 下一篇文章: SCJP Mock Exam 2(1)
相关文章:
相关软件:

