1. Analyze the following code:
class Test {
private double i;
public Test(double i) {
this.t();
this.i = i;
}
public Test() {
System.out.println("Default constructor");
this(1);
}
public void t() {
System.out.println("Invoking t");
}
}
a. this.t() may be replaced by t().
b. this.i may be replaced by i.
c. this(1) must be replaced by this(1.0).
d. this(1) must be called before System.out.println("Default constructor").
#
2. BigInteger and BigDecimal are immutable
a. false
b. true
#
3. Which of the following classes are immutable?
a. BigDecimal
b. BigInteger
c. Integer
d. Double
e. String
#
4. An aggregation relationship is usually represented as __________ in ___________.
a. a method/the aggregated class
b. a method/the aggregating class
c. a data field/the aggregating class
d. a data field/the aggregated class
#
5. Java uses _______ to reference the current object.
a. that
b. thisObject
c. this
d. null
#
6. Every instance data field f in the class can be referenced using this.f in an instance method the same class.
a. False
b. True
#
7. To create an instance of BigDecimal for 454.45, use
a. BigInteger("454.45");
b. BigInteger(454.45);
c. new BigInteger(454.45);
d. new BigDecimal("454.45");
#
8. Which of the following statements will convert a string s into a double value d?
a. d = Double.valueOf(s).doubleValue();
b. d = (new Double(s)).doubleValue();
c. d = Double.parseDouble(s);
d. All of the above.
#
9. A static data field can be accessed from any method in the same class.
a. False
b. True
#
10. A constructor can access ___________.
a. A local variable defined in any method
b. A private instance variable
c. A static variable
d. A public instance variable
#
11. What is the printout for the third statement in the main method?
public class Foo {
static int i = 0;
static int j = 0;
public static void main(String[] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}
k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}
a. j is 1
b. j is 0
c. j is 3
d. j is 2
#
12. Which of the following statements will convert a string s into i of int type?
a. i = Integer.valueOf(s).intValue();
b. i = Integer.parseInt(s);
c. i = (int)(Double.parseDouble(s));
d. i = Integer.valueOf(s);
e. i = (new Integer(s)).intValue();
#
13.
The internal state of an immutable class cannot be changed. String is an immutable class.
a. true
b. false
#
14. What is the output of the following code?
public class Test {
public static void main(String[] args) {
java.math.BigInteger x = new java.math.BigInteger("3");
java.math.BigInteger y = new java.math.BigInteger("7");
x.add(y);
System.out.println(x);
}
}
a. 3
b. 10
c. 11
d. 4
#
15. You can declare two variables with the same name in __________.
a. a method one as a formal parameter and the other as a local variable
bigdecimal转换为integerb. different methods in a class
c. a block
d. two nested blocks in a method (two nested blocks means one being inside the other)
#
16. What is the printout for the first statement in the main method?
public class Foo {
static int i = 0;
static int j = 0;
public static void main(String[] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}
k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}
a. i + j is 23
b. i + j is 5
c. i + j is 6
d. i + j is 22
#
17. Analyze the following code:
class Circle {
private double radius;
public Circle(double radius) {
radius = radius;
}
}
a. The program will compile, but you cannot create an object of Circle with a specified radius. The object will always have radius 0.
b. The program does not compile because Circle does not have a default constructor.
c. The program has a compilation error because you cannot assign radius to radius.
d. The program has a compilation error because it does not have a main method.
#
18. To create an instance of BigInteger for 454, use
a. BigInteger("454");
b. new BigInteger(454);
c. BigInteger(454);
d. new BigInteger("454");
#
19. Which of the following is poor design?
a. A method must be invoked after/before invoking another method in the same class.
b. A data field is derived from other data fields in the same class.
c. A method is an instance method, but it does not reference any instance data fields or invoke instance methods.
d. A parameter is passed from a constructor to initialize a static data field.
#
20. Which of the following statements are true?
a. The constructors must always be public.
b. A class should always contain a no-arg constructor.
c. The constructors may be protected.
d. A class should describe a single entity and all the class operations should logically fit together to support a coherent purpose.
#
21. ___________ can be accessed from any static method in the class.
a. An instance variable
b. A static variable
c. A local variable
#
22. ___________ can be accessed from any instance method in the class.
a. A static variable
b. A local variable
c. An instance variable
#
23. Every instance data field f in the class can be referenced using this.f in a static method the same class.
a. True
b. False
#
24. Which of the following can be placed in the blank line in the following code?
public class Test {
private int id;
public
void m1() {
_____.id = 45;
}
}
a. this
b. Test
#
25. Which of the following statements are correct?
a. new java.math.BigDecimal("343.445");
b. new java.math.BigDecimal(343.445);
c. new java.math.BigInteger(343);
d. new java.math.BigInteger("343");
#
26. What is the output of Integer.parseInt("10", 2)?
a. 10;
b. Invalid statement;
c. 2;
d. 1;
#
27. ___________ is attached to the class of the composing class to denote the aggregation relationship with the composed object.
a. A solid oval
b. An empty diamond
c. An empty oval
d. A solid diamond
#
28. Which of the following statements is correct?
a. Integer.parseInt("100");
b. Integer.parseInt(100, 16);
c. Integer.parseInt("12", 2);
d. Integer.parseInt("345", 8);
e. Integer.parseInt(100);
#
29. What is the printout for the first statement in the main method?
public class Test {
private int i = 0;
static int j = 0;
public static void main(String[] args) {
new Test();
}
public Test() {
i++;
j++;
int i = 1;
int j = 1;
System.out.println("i is " + j + " j is " + j);
}
}
a. i is 1 j is 0
b. i is 0 j is 1
c. i is 2 j is 2
d. i is 0 j is 0
e. i is 1 j is 1
#
30. To check whether a string s starts with a capitial letter, use the Boolean expression _________.
a. Character.isUppercase(s.at(1))
b. s.charAt(0) >= 'A' && s.charAt(0) <= 'Z'
c. s.charAt(0) >= 'A' || s.charAt(0) <= 'Z'
d. s.charAt(1) >= 'A' && s.charAt(1) <= 'Z'
e. Character.isUppercase(s)
#
31.
Which of the following statements are true about an immutable object?
a. An object type property in an immutable object must also be immutable.
b. All properties of an immutable object must be private.
c. All properties of an immutable object must be of primitive types.
d. The contents of an immutable object cannot be modified.
e. An immutable object contains no mutator methods.
#
32. To divide BigDecimal b1 by b2 and assign the result to b1, you write _________.
a. b1 = b2.divide(b1);
b. b2.divide(b1);
c. b1.divide(b2);
d. b1 = b1.divide(b2);
e. b1 = b2.divide(b1);
#
33. What is the printout for the second statement in the main method?
public class Foo {
static int i = 0;
static int j = 0;
public static void main(String[] args) {
int i = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + i + j);
}
k = i + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}
a. k is 2
b. k is 1
c. k is 3
d. k is 0
#
34. Which of the following statements convert a double value d into a string s?
a. s = (Double.valueOf(s)).toString();
b. s = (new Double(d)).toString();
c. s = String.stringOf(d);
d. s = new Double(d).stringOf();
#
35. In JDK 1.5, anal
yze the following code.
Line 1: Integer[] intArray = {1, 2, 3};
Line 2: int i = intArray[0] + intArray[1];
Line 3: int j = i + intArray[2];
Line 4: double d = intArray[0];
a. It is OK to automatically convert an Integer object to an int value in Line 2.
b. It is OK to mix an int value with an Integer object in an expression in Line 3.
c. Line 4 is OK. An int value from intArray[0] object is assigned to a double variable d.
d. It is OK to assign 1, 2, 3 to an array of Integer objects in JDK 1.5.
#
36. To add BigInteger b1 to b2, you write _________.
a. b2.add(b1);
b. b1 = b2.add(b1);
c. b2 = b1.add(b2);
d. b1.add(b2);
e. b2 = b2.add(b1);
#
37. An immutable class cannot have _______.
a. private data fields
b. no-arg constructors
c. static data fields
d. public constructors
e. public data fields
#
38. In JDK 1.5, you may directly assign a primitive data type value to a wrapper object. This is called ______________.
a. auto boxing
b. auto casting
c. auto conversion
d. auto unboxing
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论