一起学习
转载 对题目和答案谨做参考
Q1
A method is ...
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.
Q2
An object is ...
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.
Q3
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)
}
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
Q4
Given that Thing is a class, how many objects and reference variables are created by the following code?
Thing item, stuff;
item = new Thing();
Thing entity = new Thing();
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.
Q5
An instance member…
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
Q6
How do objects pass messages in Java?
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.
Q7
Given the following code, which statements are true?
class A {
int value1;
}
class B extends A {
int value2;
}
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.
Q8
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!"); }
}
1) java SmallProg
2) avac SmallProg
3) java SmallProg.java
4) javac SmallProg.java
5) java SmallProg main
Q9
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
}
}
1) a ;
2) b ;
3) c ;
4) d ;
5) e ;
Q10
Which statements are true concerning the effect of the >> and >>> operators?
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.
Q11
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();
}
}
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.
Q12
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));
}
}
1) est
2) es
3) str
4) st
5) s
Q13
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();
1) Code block A.
2) Code block B.
3) Code block C.
4) Code block D.
5) Code block E.
Q14
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.
Q15
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();
}
}
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 will 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.
Q16
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);
}
}
1) 81
2) 7
3) 11
4) 0
5) false
Q17
Which statements are true concerning the default layout manager for containers in the java.awt package?
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.
Q18
Which declarations will allow a class to be started as a standalone program?
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[])
Q19
Under which circumstances will a thread stop?
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.
Q20
When creating a class that associates a set of keys with a set of values, which of these interfaces is most applicable?
1) Collection
2) Set
3) SortedSet
4) Map
Q21
What does the value returned by the method getID() found in class java.awt.AWTEvent uniquely identify?
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.
Q22
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;
}
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();
}
}
1) 9
2) 18
3) 20
4) 21
5) 22
Q23
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
}
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) {}
Q24
How does the weighty property of the GridBagConstraints objects used in grid bag layout affect the layout of the components?
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.
Q25
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 Q4a39 {
int a = 1;
int b = 1;
int c = 1;
class Inner {
int a = 2;
int get() {
int c = 3;
// insert statement here
return c;
}
}
Q4a39() {
Inner i = new Inner();
System.out.println(i.get());
}
public static void main(String args[]) {
new Q4a39();
}
}
1) c = b;
2) c = this.a;
3) c = this.b;
4) c = Q4a39.this.a;
5) c = c;
Q26
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 Q76a9 {
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)
}
}
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).
Q27
Which methods from the String and StringBuffer classes modify the object on which they are called?
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.
Q28
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
}
}
1) x = y;
2) z = x;
3) y = (B) x;
4) z = (C) y;
5) y = (A) y;
Q29
Which of these are keywords in Java?
1) default
2) NULL
3) String
4) throws
5) long
Q30
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?
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.
Q31
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} };
1) Code fragment A.
2) Code fragment B.
3) Code fragment C.
4) Code fragment D.
5) Code fragment E.
Q32
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);
}
}
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.
Q33
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' };
1) (a == "Hello")
2) (a == b)
3) (a == c)
4) a.equals(b)
5) a.equals(d)
Q34
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) {}
}
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.
Q35
Given two collection objects referenced by col1 and col2, which of these statements are true?
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.
Q36
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;
}
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.
Q37
Which statements concerning the value of a member variable are true, when no explicit assignments have been made?
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.
Q38
Which statements describe guaranteed behavior of the garbage collection and finalization mechanisms?
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.
Q39
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) {}
}
1) Code fragment A.
2) Code fragment B.
3) Code fragment C.
4) Code fragment D.
5) Code fragment E.
Q40
Which of these statements concerning the collection interfaces are true?
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 also defined in Collection.
5) Map extends Collection.
Q41
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).
Q42
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 {}
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)
Q43
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;
i *= (int) Math.ceil(d);
i *= (int) Math.abs(d);
System.out.println(i);
}
}
1) 12
2) 18
3) 8
4) 12
5) 27
Q44
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();
}
}
1) 0 0 0
2) 0 0 1
3) 0 1 0
4) 1 0 0
5) 1 0 1
Q45
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?
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.
Q46
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);
}
}
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);
Q47
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();
}
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
下载本文示例代码
SCJP Mock Exam 1SCJP Mock Exam 1SCJP Mock Exam 1SCJP Mock Exam 1SCJP Mock Exam 1SCJP Mock Exam 1SCJP Mock Exam 1SCJP Mock Exam 1SCJP Mock Exam 1SCJP Mock Exam 1SCJP Mock Exam 1SCJP Mock Exam 1