⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scjp试题-scjpmockexam1.txt

📁 包括多年scjp认证考试的很多题库及答案
💻 TXT
📖 第 1 页 / 共 3 页
字号:
FilterWriter fw = FilterWriter(new FileWriter("file"), "UTF8"); 
fw.write(msg); 
fw.close(); 
} 

IMPLEMENTATION E: 
public void write(String msg) throws IOException { 
OutputStreamWriter osw = new OutputStreamWriter( 
new OutputStream(new File("file")), "UTF8" 
); 
osw.write(msg); 
osw.close(); 
} 

1) Implementation A. 
2) Implementation B. 
3) Implementation C. 
4) Implementation D. 
5) Implementation E. 

Q48 
Which are valid identifiers? 

1) _class 
2) $value$ 
3) zer@ 
4) ¥ngstr 
5) 2muchuq 

Q49 
What will be the result of attempting to compile and run the following program? 

public class Q28fd { 
public static void main(String args[]) { 
int counter = 0; 
l1: 
for (int i=10; i<0; i--) { 
l2: 
int j = 0; 
while (j < 10) { 
if (j > i) break l2; 
if (i == j) { 
counter++; 
continue l1; 
} 
} 
counter--; 
} 
System.out.println(counter); 
} 
} 

1) The program will fail to compile. 
2) The program will not terminate normally. 
3) The program will write 10 to the standard output. 
4) The program will write 0 to the standard output. 
5) The program will write 9 to the standard output. 




Q50 
Given the following interface definition, which definitions are valid? 

interface I { 
void setValue(int val); 
int getValue(); 
} 

DEFINITION A: 
(a) class A extends I { 
int value; 
void setValue(int val) { value = val; } 
int getValue() { return value; } 
} 

DEFINITION B: 
(b) interface B extends I { 
void increment(); 
} 

DEFINITION C: 
(c) abstract class C implements I { 
int getValue() { return 0; } 
abstract void increment(); 
} 

DEFINITION D: 
(d) interface D implements I { 
void increment(); 
} 

DEFINITION E: 
(e) class E implements I { 
int value; 
public void setValue(int val) { value = val; } 
} 

1) Definition A. 
2) Definition B. 
3) Definition C. 
4) Definition D. 
5) Definition E. 

Q51 
Which statements concerning the methods notify() and notifyAll() are true? 

1) Instances of class Thread have a method called notify(). 
2) A call to the method notify() will wake the thread that currently owns the monitor of the object. 
3) The method notify() is synchronized. 
4) The method notifyAll() is defined in class Thread. 
5) When there is more than one thread waiting to obtain the monitor of an object, there is no way to be sure which thread will be notified by the notify() method. 

Q52 
Which statements concerning the correlation between the inner and outer instances of non-static inner classes are true? 

1) Member variables of the outer instance are always accessible to inner instances, regardless of their accessibility modifiers. 
2) Member variables of the outer instance can never be referred to using only the variable name within the inner instance. 
3) More than one inner instance can be associated with the same outer instance. 
4) All variables from the outer instance that should be accessible in the inner instance must be declared final. 
5) A class that is declared final cannot have any inner classes. 

Q53 
What will be the result of attempting to compile and run the following code? 

public class Q6b0c { 
public static void main(String args[]) { 
int i = 4; 
float f = 4.3; 
double d = 1.8; 
int c = 0; 
if (i == f) c++; 
if (((int) (f + d)) == ((int) f + (int) d)) c += 2; 
System.out.println(c); 
} 
} 

1) The code will fail to compile. 
2) 0 will be written to the standard output. 
3) 1 will be written to the standard output. 
4) 2 will be written to the standard output. 
5) 3 will be written to the standard output. 




Q54 
Which operators will always evaluate all the operands? 

1) || 
2) + 
3) && 
4) ? : 
5) % 

Q55 
Which statements concerning the switch construct are true? 

1) All switch statements must have a default label. 
2) There must be exactly one label for each code segment in a switch statement. 
3) The keyword continue can never occur within the body of a switch statement. 
4) No case label may follow a default label within a single switch statement. 
5) A character literal can be used as a value for a case label. 

Q56 
Which modifiers and return types would be valid in the declaration of a working main() method for a Java standalone application? 

1) private 
2) final 
3) static 
4) int 
5) abstract 

Q57 
What will be the appearance of an applet with the following init() method? 

public void init() { 
add(new Button("hello")); 
} 

1) Nothing appears in the applet. 
2) A button will cover the whole area of the applet. 
3) A button will appear in the top left corner of the applet. 
4) A button will appear, centered in the top region of the applet. 
5) A button will appear in the center of the applet. 

Q58 
Which statements concerning the event model of the AWT are true? 

1) At most one listener of each type can be registered with a component. 
2) Mouse motion listeners can be registered on a List instance. 
3) There exists a class named ContainerEvent in package java.awt.event. 
4) There exists a class named MouseMotionEvent in package java.awt.event. 
5) There exists a class named ActionAdapter in package java.awt.event. 

Q59 
Which statements are true, given the code new FileOutputStream("data", true) for creating an object of class FileOutputStream? 

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 = '\0041'; 
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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -