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

📄 green模拟题4.htm

📁 非常好的java习题集
💻 HTM
📖 第 1 页 / 共 3 页
字号:
OutputStreamWriter(new FileOutputStream("file"), "UTF8"); <BR>osw.write(msg); 
<BR>osw.close(); <BR>} <BR><BR>IMPLEMENTATION C: <BR>public void write(String 
msg) throws IOException { <BR>FileWriter fw = new FileWriter(new File("file")); 
<BR>fw.setEncoding("UTF8"); <BR>fw.write(msg); <BR>fw.close(); <BR>} 
<BR><BR>IMPLEMENTATION D: <BR>public void write(String msg) throws IOException { 
<BR>FilterWriter fw = FilterWriter(new FileWriter("file"), "UTF8"); 
<BR>fw.write(msg); <BR>fw.close(); <BR>} <BR><BR>IMPLEMENTATION E: <BR>public 
void write(String msg) throws IOException { <BR>OutputStreamWriter osw = new 
OutputStreamWriter( <BR>new OutputStream(new File("file")), "UTF8" <BR>); 
<BR>osw.write(msg); <BR>osw.close(); <BR>} <BR><BR>1) Implementation A. <BR>2) 
Implementation B. <BR>3) Implementation C. <BR>4) Implementation D. <BR>5) 
Implementation E. <BR><BR>Q48 <BR>Which are valid identifiers? <BR><BR>1) _class 
<BR>2) $value$ <BR>3) zer@ <BR>4) &yen;ngstr <BR>5) 2muchuq <BR><BR>Q49 <BR>What 
will be the result of attempting to compile and run the following program? 
<BR><BR>public class Q28fd { <BR>public static void main(String args[]) { 
<BR>int counter = 0; <BR>l1: <BR>for (int i=10; i&lt;0; i--) { <BR>l2: <BR>int j 
= 0; <BR>while (j &lt; 10) { <BR>if (j &gt; i) break l2; <BR>if (i == j) { 
<BR>counter++; <BR>continue l1; <BR>} <BR>} <BR>counter--; <BR>} 
<BR>System.out.println(counter); <BR>} <BR>} <BR><BR>1) The program will fail to 
compile. <BR>2) The program will not terminate normally. <BR>3) The program will 
write 10 to the standard output. <BR>4) The program will write 0 to the standard 
output. <BR>5) The program will write 9 to the standard output. <BR><BR>Q50 
<BR>Given the following interface definition, which definitions are valid? 
<BR><BR>interface I { <BR>void setValue(int val); <BR>int getValue(); <BR>} 
<BR><BR>DEFINITION A: <BR>(a) class A extends I { <BR>int value; <BR>void 
setValue(int val) { value = val; } <BR>int getValue() { return value; } <BR>} 
<BR><BR>DEFINITION B: <BR>(b) interface B extends I { <BR>void increment(); 
<BR>} <BR><BR>DEFINITION C: <BR>(c) abstract class C implements I { <BR>int 
getValue() { return 0; } <BR>abstract void increment(); <BR>} <BR><BR>DEFINITION 
D: <BR>(d) interface D implements I { <BR>void increment(); <BR>} 
<BR><BR>DEFINITION E: <BR>(e) class E implements I { <BR>int value; <BR>public 
void setValue(int val) { value = val; } <BR>} <BR><BR>1) Definition A. <BR>2) 
Definition B. <BR>3) Definition C. <BR>4) Definition D. <BR>5) Definition E. 
<BR><BR>Q51 <BR>Which statements concerning the methods notify() and notifyAll() 
are true? <BR><BR>1) Instances of class Thread have a method called notify(). 
<BR>2) A call to the method notify() will wake the thread that currently owns 
the monitor of the object. <BR>3) The method notify() is synchronized. <BR>4) 
The method notifyAll() is defined in class Thread. <BR>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. <BR><BR>Q52 
<BR>Which statements concerning the correlation between the inner and outer 
instances of non-static inner classes are true? <BR><BR>1) Member variables of 
the outer instance are always accessible to inner instances, regardless of their 
accessibility modifiers. <BR>2) Member variables of the outer instance can never 
be referred to using only the variable name within the inner instance. <BR>3) 
More than one inner instance can be associated with the same outer instance. 
<BR>4) All variables from the outer instance that should be accessible in the 
inner instance must be declared final. <BR>5) A class that is declared final 
cannot have any inner classes. <BR><BR>Q53 <BR>What will be the result of 
attempting to compile and run the following code? <BR><BR>public class Q6b0c { 
<BR>public static void main(String args[]) { <BR>int i = 4; <BR>float f = 4.3; 
<BR>double d = 1.8; <BR>int c = 0; <BR>if (i == f) c++; <BR>if (((int) (f + d)) 
== ((int) f + (int) d)) c += 2; <BR>System.out.println(c); <BR>} <BR>} 
<BR><BR>1) The code will fail to compile. <BR>2) 0 will be written to the 
standard output. <BR>3) 1 will be written to the standard output. <BR>4) 2 will 
be written to the standard output. <BR>5) 3 will be written to the standard 
output. <BR><BR>Q54 <BR>Which operators will always evaluate all the operands? 
<BR><BR>1) || <BR>2) + <BR>3) &amp;&amp; <BR>4) ? : <BR>5) % <BR><BR>Q55 
<BR>Which statements concerning the switch construct are true? <BR><BR>1) All 
switch statements must have a default label. <BR>2) There must be exactly one 
label for each code segment in a switch statement. <BR>3) The keyword continue 
can never occur within the body of a switch statement. <BR>4) No case label may 
follow a default label within a single switch statement. <BR>5) A character 
literal can be used as a value for a case label. <BR><BR>Q56 <BR>Which modifiers 
and return types would be valid in the declaration of a working main() method 
for a Java standalone application? <BR><BR>1) private <BR>2) final <BR>3) static 
<BR>4) int <BR>5) abstract <BR><BR>Q57 <BR>What will be the appearance of an 
applet with the following init() method? <BR><BR>public void init() { 
<BR>add(new Button("hello")); <BR>} <BR><BR>1) Nothing appears in the applet. 
<BR>2) A button will cover the whole area of the applet. <BR>3) A button will 
appear in the top left corner of the applet. <BR>4) A button will appear, 
centered in the top region of the applet. <BR>5) A button will appear in the 
center of the applet. <BR><BR>Q58 <BR>Which statements concerning the event 
model of the AWT are true? <BR><BR>1) At most one listener of each type can be 
registered with a component. <BR>2) Mouse motion listeners can be registered on 
a List instance. <BR>3) There exists a class named ContainerEvent in package 
java.awt.event. <BR>4) There exists a class named MouseMotionEvent in package 
java.awt.event. <BR>5) There exists a class named ActionAdapter in package 
java.awt.event. <BR><BR>Q59 <BR>Which statements are true, given the code new 
FileOutputStream("data", true) for creating an object of class FileOutputStream? 
<BR><BR>1) FileOutputStream has no constructors matching the given arguments. 
<BR>2) An IOExeception will be thrown if a file named "data" already exists. 
<BR>3) An IOExeception will be thrown if a file named "data" does not already 
exist. <BR>4) If a file named "data" exists, its contents will be reset and 
overwritten. <BR>5) If a file named "data" exists, output will be appended to 
its current contents. <BR><BR>Q60 <BR>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. <BR><BR>class Base { <BR>public void print() { 
<BR>System.out.println("base"); <BR>} <BR>} <BR>class Extention extends Base { 
<BR>public void print() { <BR>System.out.println("extension"); <BR>// insert 
line of implementation here <BR>} <BR>} <BR>public class Q294d { <BR>public 
static void main(String args[]) { <BR>Extention ext = new Extention(); 
<BR>ext.print(); <BR>} <BR>} <BR><BR>Fill in a single line of implementation. 
<BR><BR><BR><BR>Q61 <BR>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? <BR><BR>1) Vector filelist = ((Directory) 
file).getList(); <BR>2) String[] filelist = file.directory(); <BR>3) Enumeration 
filelist = file.contents(); <BR>4) String[] filelist = file.list(); <BR>5) 
Vector filelist = (new Directory(file)).files(); <BR><BR>Q62 <BR>What will be 
written to the standard output when the following program is run? <BR><BR>public 
class Q03e4 { <BR>public static void main(String args[]) { <BR>String space = " 
"; <BR>String composite = space + "hello" + space + space; 
<BR>composite.concat("world"); <BR>String trimmed = composite.trim(); 
<BR>System.out.println(trimmed.length()); <BR>} <BR>} <BR><BR>1) 5 <BR>2) 6 
<BR>3) 7 <BR>4) 12 <BR>5) 13 <BR><BR>Q63 <BR>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? <BR><BR>class Counter { <BR>int v = 0; <BR>synchronized void inc() { v++; 
} <BR>synchronized void dec() { v--; } <BR>} <BR><BR>public class Q7ed5 { 
<BR>Counter i; <BR>Counter j; <BR>Counter k; <BR>public synchronized void a() { 
<BR>i.inc(); <BR>System.out.println("a"); <BR>i.dec(); <BR>} <BR>public 
synchronized void b() { <BR>i.inc(); j.inc(); k.inc(); 
<BR>System.out.println("b"); <BR>i.dec(); j.dec(); k.dec(); <BR>} <BR>public 
void c() { <BR>k.inc(); <BR>System.out.println("c"); <BR>k.dec(); <BR>} <BR>} 
<BR><BR>1) i.v is guaranteed always to be 0 or 1. <BR>2) j.v is guaranteed 
always to be 0 or 1. <BR>3) k.v is guaranteed always to be 0 or 1 <BR>4) j.v 
will always be greater than or equal to k.v at any give time. <BR>5) k.v will 
always be greater than or equal to j.v at any give time. <BR><BR>Q64 <BR>Which 
statements concerning casting and conversion are true? <BR><BR>1) Conversion 
from int to long does not need a cast. <BR>2) Conversion from byte to short does 
not need a cast. <BR>3) Conversion from float to long does not need a cast. 
<BR>4) Conversion from short to char does not need a cast. <BR>5) Conversion 
from boolean to int using a cast is not possible. <BR><BR>Q65 <BR>Given the 
following code, which method declarations, when inserted at the indicated 
position, will not cause the program to fail compilation? <BR><BR>public class 
Qdd1f { <BR>public long sum(long a, long b) { return a + b; } <BR>// insert new 
method declaration here <BR>} <BR><BR>1) public int sum(int a, int b) { return a 
+ b; } <BR>2) public int sum(long a, long b) { return 0; } <BR>3) abstract int 
sum(); <BR>4) private long sum(long a, long b) { return a + b; } <BR>5) public 
long sum(long a, int b) { return a + b; } <BR><BR>Q66 <BR>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? <BR><BR>1) char ch = 65; 
<BR>2) char ch = '\65'; <BR>3) char ch = '\0041'; <BR>4) char ch = 'A'; 
<BR>5)char ch = "A"; <BR><BR><BR>1) 4 <BR>2) 2 <BR>3) 2 <BR>4) 2, 6 <BR>5) 4 
<BR>6) 3 <BR>7) 4 <BR>8) 4 <BR>9) 1, 2, 3, 5 <BR>10) 1, 5 <BR>11) 4 <BR>12) 5 
<BR>13) 1 <BR>14) "LayoutManager layout = new GridLayout(2, 3);" <BR>or: 
"LayoutManager layout = new GridLayout(2, 3)" <BR>15) 5 <BR>16) 3 <BR>17) 2, 4 
<BR>18) 4, 5 <BR>19) 2 <BR>20) 4 <BR>21) 4 <BR>22) 5 <BR>23) 1, 2 <BR>24) 2 
<BR>25) 1, 4 <BR>26) 3 <BR>27) 4 <BR>28) 3 (? no run-time exception) <BR>29) 1, 
4, 5 <BR>30) 5 <BR>31) 2, 5 <BR>32) 1 <BR>33) 3, 4 <BR>34) 2, 3 <BR>35) 2, 4 
<BR>36) 3, 5 <BR>37) 2, 5 <BR>38) 3, 4 <BR>39) 1 <BR>40) 1, 2, 3 <BR>41) "wait" 
<BR>42) 3 <BR>43) 3 <BR>44) 5 <BR>45) 4 <BR>46) 1, 2, 3, 4 <BR>47) 2 <BR>48) 1, 
2, 4 <BR>49) 1 <BR>50) 2, 3 <BR>51) 1, 5 <BR>52) 1, 3 <BR>53) 1 <BR>54) 2, 5 
<BR>55) 5 <BR>56) 2, 3 <BR>57) 4 <BR>58) 2, 3 <BR>59) 5 <BR>60) super.print(); 
<BR>61) 4 <BR>62) 1 <BR>63) 1,2 <BR>64) 1,2,5 <BR>65) 1,5 <BR>66) 1,4 
</BODY></HTML>

⌨️ 快捷键说明

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