1.
To obtain the distance between the points (40, 50) and (5.5, 4.4), use _________.
回答错误
多选题 (2 分) 0 分
- A.
new Point2D(40, 50).distance(5.5, 4.4)
- B.
new Point2D(5.5, 4.4).distance(40, 50)
- C.
new Point2D(40, 50).distance(new Point2D(5.5, 4.4))
- D.
distance(40, 50, 5.5, 4.4)
- E.
new Point2D(5.5, 4.4).distance(new Point2D(40, 50))
3.
Suppose the xMethod() is invoked in the following constructor in a class, xMethod() is _________ in the class.
public MyClass() {
xMethod();
}
回答错误
单选题 (1 分) 0 分
- A.
an instance method
- B.
a static method or an instance method
- C.
a static method
4.
Which of the following statements are true?
多选题 (2 分) 2 分
- A.
Data fields have default values.
- B.
A variable of a reference type holds a reference to where an object is stored in the memory.
- C.
You may assign an int value to a reference variable.
- D.
Local variables do not have default values.
- E.
A variable of a primitive type holds a value of the primitive type.
5.
_______ is a construct that defines objects of the same type.
单选题 (1 分) 1 分
- A.
A method
- B.
An object
- C.
A data field
- D.
A class
6.
Variables that are shared by every instances of a class are __________.
单选题 (1 分) 1 分
- A.
instance variables
- B.
class variables
- C.
private variables
- D.
public variables
13.
Analyze the following code.
public class Test {
int x;
public Test(String t) {
System.out.println("Test");
}
public static void main(String[] args) {
Test test = null;
System.out.println(test.x);
}
}
单选题 (1 分) 1 分
- A.
The program has a compile error because x has not been initialized.
- B.
The program has a runtime NullPointerException because test is null while executing test.x.
- C.
The program has a compile error because Test does not have a default constructor.
- D.
The program has a compile error because test is not initialized.
- E.
The program has a compile error because you cannot create an object from the class that defines the object.
23.
A constructor can access ___________.
回答错误
多选题 (2 分) 0 分
- A.
A private instance variable
- B.
A static variable
- C.
A local variable defined in any method
- D.
A public instance variable
24.
An immutable class cannot have _______.
回答错误
单选题 (1 分) 0 分
- A.
no-arg constructors
- B.
private data fields
- C.
static data fields
- D.
public data fields
- E.
public constructors
30.
Which of the following statements are true about an immutable object?
回答错误
多选题 (2 分) 0 分
- A.
An immutable object contains no mutator methods.
- B.
All properties of an immutable object must be private.
- C.
The contents of an immutable object cannot be modified.
- D.
All properties of an immutable object must be of primitive types.
- E.
An object type property in an immutable object must also be immutable.
35.
You cannot use the private modifier on classes.
判断题 (1 分) 1 分
- A.
false
- B.
true
44.
Java assigns a default value to a local variable in a method if the variable is not initialized.
回答错误
判断题 (1 分) 0 分
- A.
false
- B.
true
54.
Analyze the following code and choose the best answer:
public class Foo {
private int x;
public static void main(String[] args) {
Foo foo = new Foo();
System.out.println(foo.x);
}
}
单选题 (1 分) 1 分
- A.
Since x is an instance variable, it cannot be directly used inside a main method. However, it can be accessed through an object such as foo in this code.
- B.
Since x is defined in the class Foo, it can be accessed by any method inside the class without using an object. You can write the code to access x without creating an object such as foo in this code.
- C.
Since x is private, it cannot be accessed from an object foo.
- D.
You cannot create a self-referenced object; that is, foo is created inside the class Foo.
65.
Analyze the following code:
public class Test {
private int t;
public static void main(String[] args) {
int x;
System.out.println(t);
}
}
回答错误
单选题 (1 分) 0 分
- A.
The variable t is private and therefore cannot be accessed in the main method.
- B.
t is non-static and it cannot be referenced in a static context in the main method.
- C.
The program compiles and runs fine.
- D.
The variable x is not initialized and therefore causes errors.
- E.
The variable t is not initialized and therefore causes errors.