Section(部分,节):Language Fundamentals(基本原则)
Problem[1]
A method is ...
[Select One]
[1]an implementation of an abstraction.
[2]an attribute defining the property of
a particular abstraction
[3]a category of objects.
[4]an operation defining the behavior
for a particular abstraction.
[5]a blueprint(蓝图,设计图) for making operations.
Section:Language Fundamentals
Problem[2]
An object is ...
[Select One]
[1]what classes are instantiated(例示) from.
[2]an instance of a class.
[3]a blueprint for creating concrete realization of abstractions.
[4]a reference to an attribute.
[5]a variable.
Section:Declarations and Access Control
Problem[3]
Which line contains a constructor in
this class definition?
public class Counter
{
// (1)
int current, step;
public Counter(int startValue, int
stepValue) { // (2)
set(startValue);
setStepValue(stepValue);
}
public int get() { return current; }
// (3)
public void set(int value) { current
= value; } // (4)
public void setStepValue(int
stepValue) { step = stepValue; } //
(5)
}
[Select One]
[1]Code marked with (1) is a constructor.
[2]Code marked with (2) is a constructor.
[3]Code marked with (3) is a constructor.
[4]Code marked with (4) is a constructor.
[5]Code marked with (5) is a constructor.
Section:Language Fundamentals
Problem[4]
Given that Thing is a class, how many
objects and reference variables are
created by the following code?
Thing item, stuff;
item = new Object();
Thing entity = new Object();
[Select All]
[1]One object is created.
[2]Two objects are created.
[3]Three objects are created.
[4]One reference variable is created.
[5]Two reference variables are created.
[6]Three reference variables are created.
Section:Language Fundamentals
Problem[5]
An instance member ...
[Select One]
[1]is also called a static member。
[2]is always a variable.
[3]is never a method.
[4]belongs to a single instance, not to
the class as a whole.
[5]always represents(描述) an operation.
Section:Language Fundamentals
Problem[6]
How do objects pass messages in Java?
[Select One]
[1]They pass messages by modifying each
other's member variables.
[2]They pass messages by modifying the
static member variables of each other's
classes.
[3]They pass messages by calling each
other's instance member methods.
[4]They pass messages by calling static
member methods of each other's classes.
Section:Declarations and Access Control
Problem[7]
Given the following code, which
statements are true?
class A {
int value1;
}
class B extends A {
int value2;
}
[Select All]
[1]Class A extends class B.
[2]Class B is the superclass of class A.
[3]Class A inherits from class B.
[4]Class B is a subclass of class A.
[5]Objects of class A have a member
variable named value2.
Section:Language Fundamentals
Problem[8]
If this source code is contained in a
file called SmallProg.java, what
command should be used to compile it
using the JDK?
public class SmallProg {
public static void main(String
args[]) { System.out.println("Good
luck!"); }
}
[Select One]
[1]java SmallProg
[2]javac SmallProg
[3]java SmallProg.java
[4]javac SmallProg.java
[5]java SmallProg main
Section:Declarations and Access Control
Problem[9]
Given the following class, which
statements can be inserted at position
1 without causing the code to fail
compilation?
public class Q6db8 {
int a;
int b = 0;
static int c;
public void m() {
int d;
int e = 0;
// Position 1
}
}
[Select All]
[1]a++;
[2]b++;
[3]c++;
[4]d++;
[5]e++;
Section:Operators and Assignments(分配)
Problem[10]
Which statements are true concerning the
effect of the >> and >>> operators?
[Select All]
[1]For non-negative(正的,非负的) values of the left
Operand操作数, the >> and >>> operators will
have the same effect.
[2]The result of (-1 >> 1) is 0.
[3]The result of (-1 >>> 1) is -1.
[4]The value returned by >>> will never
be negative as long as the value of the
right operand is equal to or greater than
1.
[5]When using the >> operator, the
Leftmost bit of the bit representation(表示法)
of the resulting value will always be the
same bit value as the leftmost bit of the
bit representation of the left operand.
Section:Flow Control and Exception
Handling
Problem[11]
What is wrong with the following code?
class MyException extends Exception {}
public class Qb4ab {
public void foo() {
try {
bar();
} finally {
baz();
} catch (MyException e) {}
}
public void bar() throws
MyException {
throw new MyException();
}
public void baz() throws
RuntimeException {
throw new RuntimeException();
}
}
[Select All]
[1]Since the method foo() does not catch
the exception generated by the method
baz(), it must declare the
RuntimeException in its throws clause.
[2]A try block cannot be followed by both
a catch and a finally block.
[3]An empty catch block is not allowed.
[4]A catch block cannot follow a finally
block.
[5]A finally block must always follow
one or more catch blocks.
Section:The java.lang package
Problem[12]
What will be written to the standard
output when the following program is run?
public class Qd803 {
public static void main(String
args[]) {
String word = "restructure";
System.out.println(word.substring(2,
3));
}
}
[Select One]
[1]est
[2]es
[3]str
[4]st
[5]s
Section:Threads
Problem[13]
Given that a static method doIt() in a
class Work represents work to be done,
what block of code will succeed in
starting a new thread that will do the
work?
CODE BLOCK A:
Runnable r = new Runnable() {
public void run() {
Work.doIt();
}
};
Thread t = new Thread(r);
t.start();
CODE BLOCK B:
Thread t = new Thread() {
public void start() {
Work.doIt();
}
};
t.start();
CODE BLOCK C:
Runnable r = new Runnable() {
public void run() {
Work.doIt();
}
};
r.start();
CODE BLOCK D:
Thread t = new Thread(new Work());
t.start();
CODE BLOCK E:
Runnable t = new Runnable() {
public void run() {
Work.doIt();
}
};
t.run();
[Select All]
[1]Code block A.
[2]Code block B.
[3]Code block C.
[4]Code block D.
[5]Code block E.
Section:The java.awt package - Layout
Problem[14]
Write a line of code that declares a
variable named layout of type
LayoutManager and initializes it with a
new object, which when used with a
container can lay out components in a
rectangular(矩形的) grid(格子) of equal-sized
rectangles(长方形), 3 components wide and 2
components high.
[Fill in Blank]
[Possible Solutions]
[1]LayoutManager layout = new
GridLayout(2, 3);
[2]LayoutManager layout = new
GridLayout(2, 3)
Section:Declarations and Access Control
Problem[15]
Declarations and Access Control
public class Q275d {
static int a;
int b;
public Q275d() {
int c;
c = a;
a++;
b += c;
}
public static void main(String
args[]) {
new Q275d();
}
}
[Select One]
[1]The code will fail to compile, since
the constructor is trying to access
static members.
[2]The code will fail to compile, since
the constructor is trying to use static
member variable a before it has been
initialized.
[3]The code w ill fail to compile, since
the constructor is trying to use member
variable b before it has been
initialized.
[4]The code will fail to compile, since
the constructor is trying to use local
variable c before it has been
initialized.
[5]The code will compile and run without
any problems.
Section:Operators and Assignments
Problem[16]
What will be written to the standard
output when the following program is run?
public class Q63e3 {
public static void main(String
args[]) {
System.out.println(9 ^ 2);
}
}
[Select One]
[1]81
[2]7
[3]11
[4]0
[5]false
Section:The java.awt package - Layout
Problem[17]
Which statements are true concerning(关于) the
default layout manager for containers in
the java.awt package?
[Select All] flowLayout:Applet Panel BorderLayout:JApplet JFrame Frame
[1]Objects instantiated from Panel do
not have a default layout manager.
[2]Objects instantiated from Panel have
FlowLayout as default layout manager.
[3]Objects instantiated from Applet
have BorderLayout as default layout
manager.
[4]Objects instantiated from Dialog
have BorderLayout as default layout
manager.
[5]Objects instantiated from Window
have the same default layout manager as
instances of Applet.
Section:Language Fundamentals
Problem[18]
Which declarations will allow a class to
be started as a standalone program?
[Select All]
[1]public void main(String args[])
[2]public void static main(String
args[])
[3]public static main(String[] argv)
[4]final public static void main(String
[] array)
[5]public static void main(String
args[])
Section:Threads
Problem[19]
Under which circumstances(环境) will a thread
stop?
[Select All]
[1]The method waitforId() in class
MediaTracker is called.
[2]The run() method that the thread is
executing ends.
[3]The call to the start() method of the
Thread object returns.
[4]The suspend() method is called on the
Thread object.
[5]The wait() method is called on the
Thread object.
Section:The java.util package
Problem[20]
When creating a class that associates(联系) a
set of keys with a set of values, which
of these interfaces is most applicable(可适用的)?
[Select One]
[1]Collection
[2]Set
[3]SortedSet
[4]Map
Section:Language Fundamentals
Problem[21]
What does the value returned by the
method getID() found in class
java.awt.AWTEvent uniquely(独特的,无一的) identify(识别,鉴定)?
[Select One]
[1]The particular event instance.
[2]The source of the event.
[3]The set of events that were triggered(触发的)
by the same action.
[4]The type of event.
[5]The type of component from which the
event originated.
Section:Overloading Overriding Runtime
Type and Object Orientation(方向,方位)
Problem[22]
What will be written to the standard
output when the following program is run?
class Base {
int i;
Base() {
add(1);
}
void add(int v) {
i += v; i=1
}
void print() {
System.out.println(i);
}
}
class Extension extends Base {
Extension() {
add(2);
}
void add(int v) {
i += v*2;
}
}
public class Qd073 {
public static void main(String
args[]) {
bogo(new Extension());
}
static void bogo(Base b) {
b.add(8);
b.print();
}
}
[Select One]
[1]9
[2]18
[3]20
[4]21
[5]22
Section:Declarations and Access Control
Problem[23]
Which lines of code are valid
declarations of a native method when
occurring within the declaration of the
following class?
public class Qf575 {
// insert declaration of a native
method here
}
[Select All]
[1]native public void
setTemperature(int kelvin);
[2]private native void
setTemperature(int kelvin);
[3]protected int native
getTemperature();
[4]public abstract native void
setTemperature(int kelvin);
[5]native int setTemperature(int kelvin)
{}
Section:The java.awt package - Layout
Problem[24]
How does the weighty property of the
GridBagConstraints objects used in grid
bag layout affect the layout of the
components?
[Select One]
[1]It affects which grid cell the
components end up in.
[2]It affects how the extra vertical(垂直的)
space is distributed.
[3]It affects the alignment of each
component.
[4]It affects whether the components
completely fill their allotted display
area vertically.
Section:Overloading Overriding Runtime
Type and Object Orientation
Problem[25]
Which statements can be inserted at the
Indicated(指出的) position in the following code
to make the program write 1 on the
standard output when run?
public class Q 4a 39 {
int a = 1;
int b = 1;
int c = 1;
class Inner {
int a = 2;
int get() {
int c = 3;
// insert statement here
return c;
}
}
Q 4a 39() {
Inner i = new Inner();
System.out.println(i.get());
}
public static void main(String
args[]) {
new Q 4a 39();
}
}
[Select All]
[1]c = b;
[2]c = this.a;
[3]c = this.b;
[4]c = Q 4a 39.this.a;
[5]c = c;
Section:Garbage Collection(碎片收集)
Problem[26]
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?
public class Q 76a 9 {
static String f() {
String a = "hello";
String b = "bye"; //
(0)
String c = b + "!"; //
(1)
String d = b;
b = a;
// (2)
d = a;
// (3)
return c;
// (4)
}
public static void main(String
args[]) {
String msg = f();
System.out.println(msg);
// (5)
}
}
[Select One]
[1]The line marked (1).
[2]The line marked (2).
[3]The line marked (3).
[4]The line marked (4).
[5]The line marked (5).
Section:The java.lang package
Problem[27]
Which methods from the String and
StringBuffer classes modify(修改) the object
on which they are called?
[Select All]
[1]The charAt() method of the String
class.
[2]The toUpperCase() method of the
String class.
[3]The replace() method of the String
class.
[4]The reverse() method of the
StringBuffer class.
[5]The length() method of the
StringBuffer class.
Section:Overloading Overriding Runtime
Type and Object Orientation
Problem[28]
Which statements, when inserted at the
indicated position in the following code,
will cause a runtime exception when
attempting to run the program?
class A {}
class B extends A {}
class C extends A {}
public class Q3ae4 {
public static void main(String
args[]) {
A x = new A();
B y = new B();
C z = new C();
// insert statement here
}
}
[Select All]
[1]x = y;
[2]z = x;
[3]y = (B) x;
[4]z = (C) y;
[5]y = (A) y;
运行时异常而不是编译时异常
Section:Language Fundamentals
Problem[29]
Which of these are keywords in Java?
[Select All]
[1]default
[2]NULL null
[3]String string
[4]throws
[5]long
Section:Declarations and Access Control
Problem[30]
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(强迫)?
[Select One]
[1]Mark the method with the keyword
public.
[2]Mark the method with the keyword
protected.
[3]Mark the method with the keyword
private.
[4]Mark the method with the keyword
package.
[5]Do not mark the method with any
accessibility modifiers.
Package不是关键字
Section:Declarations and Access Control
Problem[31]
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?
CODE FRAGMENT A:
int[][] tab = {
{ 0, 0, 0 },
{ 0, 0, 0 }
};
CODE FRAGMENT B:
int tab[][] = new int[4][];
for (int i=0; i
CODE FRAGMENT C:
int tab[][] = {
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0
};
CODE FRAGMENT D:
int tab[3][2];
CODE FRAGMENT E:
int[] tab[] = { {0, 0, 0}, {0, 0, 0},
{0, 0, 0}, {0, 0, 0} };
[Select 2]
[1]Code fragment A.
[2]Code fragment B.
[3]Code fragment C.
[4]Code fragment D.
[5]Code fragment E.
Section:Operators and Assignments
Problem[32]
What will be the result of attempting to
run the following program?
public class Qaa75 {
public static void main(String
args[]) {
String[][][] arr = {
{ {}, null },
{ { "1", "2" } , { "1", null,
"3" } },
{},
{ { "1", null } }
};
System.out.println(arr.length
+ arr[1][2].length);
}
}
[Select One]
[1]The program will terminate(终止) with an
ArrayIndexOutOfBoundsException.
[2]The program will terminate with a
NullPointerException.
[3]4 will be written to standard output.
[4]6 will be written to standard output.
[5]7 will be written to standard output.
Section:Operators and Assignments
Problem[33]
Which expressions will evaluate to true
if preceded(加上) by the following code?
String a = "hello";
String b = new String(a);
String c = a;
char[] d = { 'h', 'e', 'l', 'l', 'o' };
[Select All]
[1](a == "Hello") 小写和大写
[2](a == b)
[3](a == c)
[4]a.equals(b)
[5]a.equals(d) 不是同一个类型
Section:Overloading Overriding Runtime
Type and Object Orientation(定位,方位,方向)
Problem[34]
Which statements concerning(关于) the
following code are true?
class A {
public A() {}
public A(int i) { this(); }
}
class B extends A {
public boolean B(String msg)
{ return false; }
}
class C extends B {
private C() { super(); }
public C(String msg) { this(); }
public C(int i) {}
}
[Select All]
[1]The code will fail to compile.
[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.
[3]Class C has three constructors.
[4]Objects of class B cannot be
constructed.
[5]At most one of the constructors of
each class is called as a result of
constructing an object of class C.
Section:The java.util package
Problem[35]
Given two collection objects referenced(参考的,引用的)
by col1 and col2, which of these
statements are true?
[Select All]
[1]The operation col1.retainAll(col2)
will not modify the col1 object.
[2]The operation col1.removeAll(col2)
will not modify the col2 object.
[3]The operation col1.addAll(col2) will
return a new collection object,
containing elements from both col1 and
col2.
[4]The operation col1.containsAll(Col2)
will not modify the col1 object.
Section:Overloading Overriding Runtime
Type and Object Orientation
Problem[36]
Which statements concerning the
relationships between the following
classes are true?
class Foo {
int num;
Baz comp = new Baz();
}
class Bar {
boolean flag;
}
class Baz extends Foo {
Bar thing = new Bar();
double limit;
}
[Select 2]
[1]A Bar is a Baz.
[2]A Foo has a Bar.
[3]A Baz is a Foo.
[4]A Foo is a Baz.
[5]A Baz has a Bar.
子类是父类----继承
一个类中有另一个类对象
Section:Declarations and Access Control
Problem[37]
Which statements concerning the value of
a member variable are true, when no
explicit assignments have been made?
[Select All]
[1]The value of an int is undetermined.
[2]The value of all numeric types is zero.
[3]The compiler may issue(发布,发出) an error if the
variable is used before it is
initialized.
[4]The value of a String variable is ""
(empty string).
[5]The value of all object variables is
null.
Section:Garbage Collection
Problem[38]
Which statements describe guaranteed(保证,担保)
behavior of the garbage collection and
finalization mechanisms?
[Select All]
[1]Objects are deleted when they can no
longer be accessed through any reference.
[2]The finalize() method will
eventually be called on every object.
[3]The finalize() method will never be
called more than once on an object.
[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.
[5]The garbage collector will use a mark
and sweep algorithm(运算法则).
Section:Language Fundamentals
Problem[39]
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?
CODE FRAGMENT A:
public static void main(String
args[]) {
if (args.length != 0)
System.out.println(args[args.length-1
]);
}
CODE FRAGMENT B:
public static void main(String
args[]) {
try
{ System.out.println(args[args.length
]); }
catch
(ArrayIndexOutOfBoundsException e) {}
}
CODE FRAGMENT C:
public static void main(String
args[]) {
int ix = args.length;
String last = args[ix];
if (ix != 0)
System.out.println(last);
}
CODE FRAGMENT D:
public static void main(String
args[]) {
int ix = args.length-1;
if (ix > 0)
System.out.println(args[ix]);
}
CODE FRAGMENT E:
public static void main(String
args[]) {
try
{ System.out.println(args[args.length
-1]); }
catch (NullPointerException e)
{}
}
[Select All]
[1]Code fragment A.
[2]Code fragment B.
[3]Code fragment C.
[4]Code fragment D.
[5]Code fragment E.
Section:The java.util package
Problem[40]
Which of these statements concerning the
collection interfaces are true?
[Select All]
[1]Set extends Collection.
[2]All methods defined in Set are also
defined in Collection.
[3]List extends Collection.
[4]All methods defined in List are a lso
defined in Collection.
[5]Map extends Collection.
Section:Threads
Problem[41]
What is the name of the method that
threads can use to pause their execution
until signalled(告知) to continue by another
thread?
Fill in the name of the method (do not
include a parameter list).
[Fill in Blank]
[Possible Solutions]
[1]wait
Section:Overloading Overriding Runtime
Type and Object Orientation
Problem[42]
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?
class A {}
class B extends A {}
class C extends B {}
class D extends A {}
[Select All]
[1]obj instanceof B
[2]obj instanceof A && ! (obj instanceof
C)
[3]obj instanceof B && ! (obj instanceof
C)
[4]obj instanceof C || obj instanceof D
[5]obj instanceof A) && ! (obj
instanceof C) && ! (obj instanceof D)
Section:The java.lang package
Problem[43]
What will be written to the standard
output when the following program is run?
public class Q8499 {
public static void main(String
args[]) {
double d = -2.9;
int i = (int) d; -2
i *= (int) Math.ceil(d); 4
i *= (int) Math.abs(d);
System.out.println(i);
}
}
[Select One]
[1]12
[2]18
[3]8
[4]12
[5]27
Section:Operators and Assignments
Problem[44]
What will be written to the standard
output when the following program is run?
public class Qcb90 {
int a;
int b;
public void f() {
a = 0;
b = 0;
int[] c = { 0 };
g(b, c);
System.out.println(a + " " + b
+ " " + c[0] + " ");
}
public void g(int b, int[] c) {
a = 1;
b = 1;
c[0] = 1;
}
public static void main(String
args[]) {
Qcb90 obj = new Qcb90();
obj.f();
}
}
[Select One]
[1]0 0 0
[2]0 0 1
[3]0 1 0
[4]1 0 0
[5]1 0 1
Section:The java.awt package - Painting
Problem[45]
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?
[Select All]
[1]The rectangle(长方形) drawn will have a total
width of 5 pixels.
[2]The rectangle drawn will have a total
height of 6 pixels.
[3]The rectangle drawn will have a total
width of 10 pixels.
[4]The rectangle drawn will have a total
height of 11 pixels.
Section:The java.awt package - Layout
Problem[46]
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?
import java.awt.*;
public class Q1e65 {
public static void main(String
args[]) {
Window win = new Frame();
Button but = new
Button("button");
// insert code fragment here
win.setSize(200, 200);
win.setVisible(true);
}
}
[Select All]
[1]win.setLayout(new BorderLayout());
win.add(but);
[2]win.setLayout(new GridLayout(1, 1));
win.add(but);
[3]win.setLayout(new BorderLayout());
win.add(but, BorderLayout.CENTER);
[4]win.add(but);
[5]win.setLayout(new FlowLayout());
win.add(but);
Section:The java.io package
Problem[47]
Which method implementations will write
the given string to a file named "file",
using UTF8 encoding?
IMPLEMENTATION A:
public void write(String msg)
throws IOException {
FileWriter fw = new
FileWriter(new File("file"));
fw.write(msg);
fw.close();
}
IMPLEMENTATION B:
public void write(String msg)
throws IOException {
OutputStreamWriter osw =
new OutputStreamWriter(new
FileOutputStream("file"), "UTF8");
osw.write(msg);
osw.close();
}
IMPLEMENTATION C:
public void write(String msg)
throws IOException {
FileWriter fw = new
FileWriter(new File("file"));
fw.setEncoding("UTF8");
fw.write(msg);
fw.close();
}
IMPLEMENTATION D:
public void write(String msg)
throws IOException {
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();
}
[Select All]
[1]Implementation A.
[2]Implementation B.
[3]Implementation C.
[4]Implementation D.
[5]Implementation E.
Section:Language Fundamentals
Problem[48]
Which are valid identifiers(标识符)?
[Select All]
[1]_class
[2]$value$
[3]zer@
[4]?ngstr?m
[5]2much
Section:Flow Control and Exception
Handling
Problem[49]
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);
}
}
[Select One]
[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.
Section:Overloading Overriding Runtime
Type and Object Orientation
Problem[50]
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; }
}
[Select All]
[1]Definition A.
[2]Definition B.
[3]Definition C.
[4]Definition D.
[5]Definition E.
Section:Threads
Problem[51]
Which statements concerning the methods
notify() and notifyAll() are true?
[Select All]
[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.
Section:Overloading Overriding Runtime
Type and Object Orientation
Problem[52]
Which statements concerning the
correlation between the inner and outer
instances of non-static inner classes
are true?
[Select All]
[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 t hat is declared final cannot
have any inner classes.
Section:Operators and Assignments
Problem[53]
What will be the result of attempting to
compile and run the following code?
public class Q6b 0c {
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);
}
}
[Select One]
[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.
Section:Operators and Assignments
Problem[54]
Which operators will always evaluate all
the operands?
[Select All]
[1]||
[2]+
[3]&&
[4]? :
[5]%
Section:Flow Control and Exception
Handling
Problem[55]
Which statements concerning the switch
construct are true?
[Select All]
[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.
Section:Language Fundamentals
Problem[56]
Which modifiers and return types would
be valid in the declaration of a working
main() method for a Java standalone
application?
[Select All]
[1]private
[2]final
[3]static
[4]int
[5]abstract
Section:The java.awt package - Layout
Problem[57]
What will be the appearance of an applet
with the following init() method?
public void init() {
add(new Button("hello"));
}
[Select One]
[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.
Section:Language Fundamentals
Problem[58]
Which statements concerning the event
model of the AWT are true?
[Select All]
[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.
Section:The java.io package
Problem[59]
Which statements are true, given the
code new FileOutputStream("data", true)
for creating an object of class
FileOutputStream?
[Select All]
[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.
Section:Overloading Overriding Runtime
Type and Object Orientation
Problem[60]
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.
[Fill in Blank]
[Possible Solutions]
[1]super.print()
[2]super.print();
Section:The java.io package
Problem[61]
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?
[Select All]
[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();
Section:The java.lang package
Problem[62]
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());
}
}
[Select One]
[1]5
[2]6
[3]7
[4]12
[5]13
Section:Threads
Problem[63]
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();
}
}
[Select All]
[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.
Section:Operators and Assignments
Problem[64]
Which statements concerning casting and
conversion are true?
[Select All]
[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.
Section:Operators and Assignments
Problem[65]
Given the following code, which method
declarations, when inserted at the indicated(指出)
position, will not cause the program to fail
compilation?
public class Qdd 1f {
public long sum(long a, long b) { return a
+ b; }
// insert new method declaration here
}
[Select All]
[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; }
Section:Operators and Assignments
Problem[66]
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?
[Select All]
[1]char ch = 65;
[2]char ch = '/65';
[3]char ch = '/0041';
[4]char ch = 'A';
[5]char ch = "A";
__