📄 green模拟题4.htm
字号:
<BR>// insert statement here <BR>return c; <BR>} <BR>} <BR>Q4a39() { <BR>Inner i
= new Inner(); <BR>System.out.println(i.get()); <BR>} <BR>public static void
main(String args[]) { <BR>new Q4a39(); <BR>} <BR>} <BR><BR>1) c = b; <BR>2) c =
this.a; <BR>3) c = this.b; <BR>4) c = Q4a39.this.a; <BR>5) c = c; <BR><BR>Q26
<BR>Which is the earliest line in the following code after which the object
created on the line marked (0) will be a candidate for being garbage collected,
assuming no compiler optimizations are done? <BR><BR>public class Q76a9 {
<BR>static String f() { <BR>String a = "hello"; <BR>String b = "bye"; // (0)
<BR>String c = b + "!"; // (1) <BR>String d = b; <BR>b = a; // (2) <BR>d = a; //
(3) <BR>return c; // (4) <BR>} <BR>public static void main(String args[]) {
<BR>String msg = f(); <BR>System.out.println(msg); // (5) <BR>} <BR>} <BR><BR>1)
The line marked (1). <BR>2) The line marked (2). <BR>3) The line marked (3).
<BR>4) The line marked (4). <BR>5) The line marked (5). <BR><BR>Q27 <BR>Which
methods from the String and StringBuffer classes modify the object on which they
are called? <BR><BR>1) The charAt() method of the String class. <BR>2) The
toUpperCase() method of the String class. <BR>3) The replace() method of the
String class. <BR>4) The reverse() method of the StringBuffer class. <BR>5) The
length() method of the StringBuffer class. <BR><BR>Q28 <BR>Which statements,
when inserted at the indicated position in the following code, will cause a
runtime exception when attempting to run the program? <BR><BR>class A {}
<BR>class B extends A {} <BR>class C extends A {} <BR>public class Q3ae4 {
<BR>public static void main(String args[]) { <BR>A x = new A(); <BR>B y = new
B(); <BR>C z = new C(); <BR>// insert statement here <BR>} <BR>} <BR><BR>1) x =
y; <BR>2) z = x; <BR>3) y = (B) x; <BR>4) z = (C) y; <BR>5) y = (A) y;
<BR><BR>Q29 <BR>Which of these are keywords in Java? <BR><BR>1) default <BR>2)
NULL <BR>3) String <BR>4) throws <BR>5) long <BR><BR>Q30 <BR>It is desirable
that a certain method within a certain class can only be accessed by classes
that are defined within the same package as the class of the method. How can
such restrictions be enforced? <BR><BR>1) Mark the method with the keyword
public. <BR>2) Mark the method with the keyword protected. <BR>3) Mark the
method with the keyword private. <BR>4) Mark the method with the keyword
package. <BR>5) Do not mark the method with any accessibility modifiers.
<BR><BR>Q31 <BR>Which code fragments will succeed in initializing a
two-dimensional array named tab with a size that will cause the expression
tab[3][2] to access a valid element? <BR><BR>CODE FRAGMENT A: <BR>int[][] tab =
{ <BR>{ 0, 0, 0 }, <BR>{ 0, 0, 0 } <BR>}; <BR><BR>CODE FRAGMENT B: <BR>int
tab[][] = new int[4][]; <BR>for (int i=0; i<TAB.LENGTH; <br int[3]; tab[i]="new"
i++)> <BR>CODE FRAGMENT C: <BR>int tab[][] = { <BR>0, 0, 0, 0, <BR>0, 0, 0, 0,
<BR>0, 0, 0, 0, <BR>0, 0, 0, 0 <BR>}; <BR><BR>CODE FRAGMENT D: <BR>int
tab[3][2]; <BR><BR>CODE FRAGMENT E: <BR>int[] tab[] = { {0, 0, 0}, {0, 0, 0},
{0, 0, 0}, {0, 0, 0} }; <BR><BR>1) Code fragment A. <BR>2) Code fragment B.
<BR>3) Code fragment C. <BR>4) Code fragment D. <BR>5) Code fragment E.
<BR><BR>Q32 <BR>What will be the result of attempting to run the following
program? <BR><BR>public class Qaa75 { <BR>public static void main(String args[])
{ <BR>String[][][] arr = { <BR>{ {}, null }, <BR>{ { "1", "2" }, { "1", null,
"3" } }, <BR>{}, <BR>{ { "1", null } } <BR>}; <BR>System.out.println(arr.length
+ arr[1][2].length); <BR>} <BR>} <BR><BR>1) The program will terminate with an
ArrayIndexOutOfBoundsException. <BR>2) The program will terminate with a
NullPointerException. <BR>3) 4 will be written to standard output. <BR>4) 6 will
be written to standard output. <BR>5) 7 will be written to standard output.
<BR><BR>Q33 <BR>Which expressions will evaluate to true if preceded by the
following code? <BR><BR>String a = "hello"; <BR>String b = new String(a);
<BR>String c = a; <BR>char[] d = { 'h', 'e', 'l', 'l', 'o' }; <BR><BR>1) (a ==
"Hello") <BR>2) (a == b) <BR>3) (a == c) <BR>4) a.equals(b) <BR>5) a.equals(d)
<BR><BR>Q34 <BR>Which statements concerning the following code are true?
<BR><BR>class A { <BR>public A() {} <BR>public A(int i) { this(); } <BR>}
<BR>class B extends A { <BR>public boolean B(String msg) { return false; } <BR>}
<BR>class C extends B { <BR>private C() { super(); } <BR>public C(String msg) {
this(); } <BR>public C(int i) {} <BR>} <BR><BR>1) The code will fail to compile.
<BR>2) The constructor in A that takes an int as an argument will never be
called as a result of constructing an object of class B or C. <BR>3) Class C has
three constructors. <BR>4) Objects of class B cannot be constructed. <BR>5) At
most one of the constructors of each class is called as a result of constructing
an object of class C. <BR><BR>Q35 <BR>Given two collection objects referenced by
col1 and col2, which of these statements are true? <BR><BR>1) The operation
col1.retainAll(col2) will not modify the col1 object. <BR>2) The operation
col1.removeAll(col2) will not modify the col2 object. <BR>3) The operation
col1.addAll(col2) will return a new collection object, <BR>containing elements
from both col1 and col2. <BR>4) The operation col1.containsAll(Col2) will not
modify the col1 object. <BR><BR>Q36 <BR>Which statements concerning the
relationships between the following classes are true? <BR><BR>class Foo {
<BR>int num; <BR>Baz comp = new Baz(); <BR>} <BR>class Bar { <BR>boolean flag;
<BR>} <BR>class Baz extends Foo { <BR>Bar thing = new Bar(); <BR>double limit;
<BR>} <BR><BR>1) A Bar is a Baz. <BR>2) A Foo has a Bar. <BR>3) A Baz is a Foo.
<BR>4) A Foo is a Baz. <BR>5) A Baz has a Bar. <BR><BR>Q37 <BR>Which statements
concerning the value of a member variable are true, when no explicit assignments
have been made? <BR><BR>1) The value of an int is undetermined. <BR>2) The value
of all numeric types is zero. <BR>3) The compiler may issue an error if the
variable is used before it is initialized. <BR>4) The value of a String variable
is "" (empty string). <BR>5) The value of all object variables is null.
<BR><BR>Q38 <BR>Which statements describe guaranteed behavior of the garbage
collection and finalization mechanisms? <BR><BR>1) Objects are deleted when they
can no longer be accessed through any reference. <BR>2) The finalize() method
will eventually be called on every object. <BR>3) The finalize() method will
never be called more than once on an object. <BR>4) An object will not be
garbage collected as long as it is possible for an active part of the program to
access it through a reference. <BR>5) The garbage collector will use a mark and
sweep algorithm. <BR><BR>Q39 <BR>Which code fragments will succeed in printing
the last argument given on the command line to the standard output, and exit
gracefully with no output if no arguments are given? <BR><BR>CODE FRAGMENT A:
<BR>public static void main(String args[]) { <BR>if (args.length != 0)
<BR>System.out.println(args[args.length-1]); <BR>} <BR><BR>CODE FRAGMENT B:
<BR>public static void main(String args[]) { <BR>try {
System.out.println(args[args.length]); } <BR>catch
(ArrayIndexOutOfBoundsException e) {} <BR>} <BR><BR>CODE FRAGMENT C: <BR>public
static void main(String args[]) { <BR>int ix = args.length; <BR>String last =
args[ix]; <BR>if (ix != 0) System.out.println(last); <BR>} <BR><BR>CODE FRAGMENT
D: <BR>public static void main(String args[]) { <BR>int ix = args.length-1;
<BR>if (ix > 0) System.out.println(args[ix]); <BR>} <BR><BR>CODE FRAGMENT E:
<BR>public static void main(String args[]) { <BR>try {
System.out.println(args[args.length-1]); } <BR>catch (NullPointerException e) {}
<BR>} <BR><BR>1) Code fragment A. <BR>2) Code fragment B. <BR>3) Code fragment
C. <BR>4) Code fragment D. <BR>5) Code fragment E. <BR><BR>Q40 <BR>Which of
these statements concerning the collection interfaces are true? <BR><BR>1) Set
extends Collection. <BR>2) All methods defined in Set are also defined in
Collection. <BR>3) List extends Collection. <BR>4) All methods defined in List
are also defined in Collection. <BR>5) Map extends Collection. <BR><BR>Q41
<BR>What is the name of the method that threads can use to pause their execution
until signalled to continue by another thread? <BR><BR>Fill in the name of the
method (do not include a parameter list). <BR><BR>Q42 <BR>Given the following
class definitions, which expression identifies whether the object referred to by
obj was created by instantiating class B rather than classes A, C and D?
<BR><BR>class A {} <BR>class B extends A {} <BR>class C extends B {} <BR>class D
extends A {} <BR><BR>1) obj instanceof B <BR>2) obj instanceof A && !
(obj instanceof C) <BR>3) obj instanceof B && ! (obj instanceof C)
<BR>4) obj instanceof C || obj instanceof D <BR>5) (obj instanceof A) &&
! (obj instanceof C) && ! (obj instanceof D) <BR><BR>Q43 <BR>What will
be written to the standard output when the following program is run?
<BR><BR>public class Q8499 { <BR>public static void main(String args[]) {
<BR>double d = -2.9; <BR>int i = (int) d; <BR>i *= (int) Math.ceil(d); <BR>i *=
(int) Math.abs(d); <BR>System.out.println(i); <BR>} <BR>} <BR><BR>1) 12 <BR>2)
18 <BR>3) 8 <BR>4) 12 <BR>5) 27 <BR><BR>Q44 <BR>What will be written to the
standard output when the following program is run? <BR><BR>public class Qcb90 {
<BR>int a; <BR>int b; <BR>public void f() { <BR>a = 0; <BR>b = 0; <BR>int[] c =
{ 0 }; <BR>g(b, c); <BR>System.out.println(a + " " + b + " " + c[0] + " ");
<BR>} <BR>public void g(int b, int[] c) { <BR>a = 1; <BR>b = 1; <BR>c[0] = 1;
<BR>} <BR>public static void main(String args[]) { <BR>Qcb90 obj = new Qcb90();
<BR>obj.f(); <BR>} <BR>} <BR><BR>1) 0 0 0 <BR>2) 0 0 1 <BR>3) 0 1 0 <BR>4) 1 0 0
<BR>5) 1 0 1 <BR><BR>Q45 <BR>Which statements concerning the effect of the
statement gfx.drawRect(5, 5, 10, 10) are true, given that gfx is a reference to
a valid Graphics object? <BR><BR>1) The rectangle drawn will have a total width
of 5 pixels. <BR>2) The rectangle drawn will have a total height of 6 pixels.
<BR>3) The rectangle drawn will have a total width of 10 pixels. <BR>4) The
rectangle drawn will have a total height of 11 pixels. <BR><BR>Q46 <BR>Given the
following code, which code fragments, when inserted at the indicated location,
will succeed in making the program display a button spanning the whole window
area? <BR><BR>import java.awt.*; <BR>public class Q1e65 { <BR>public static void
main(String args[]) { <BR>Window win = new Frame(); <BR>Button but = new
Button("button"); <BR>// insert code fragment here <BR>win.setSize(200, 200);
<BR>win.setVisible(true); <BR>} <BR>} <BR><BR>1) win.setLayout(new
BorderLayout()); win.add(but); <BR>2) win.setLayout(new GridLayout(1, 1));
win.add(but); <BR>3) win.setLayout(new BorderLayout()); win.add(but,
BorderLayout.CENTER); <BR>4) win.add(but); <BR>5) win.setLayout(new
FlowLayout()); win.add(but); <BR><BR>Q47 <BR>Which method implementations will
write the given string to a file named "file", using UTF8 encoding?
<BR><BR>IMPLEMENTATION A: <BR>public void write(String msg) throws IOException {
<BR>FileWriter fw = new FileWriter(new File("file")); <BR>fw.write(msg);
<BR>fw.close(); <BR>} <BR><BR>IMPLEMENTATION B: <BR>public void write(String
msg) throws IOException { <BR>OutputStreamWriter osw = <BR>new
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -