Java 面向对象程序设计 错题整理 chapter 13

6.

The java.util.Calendar and java.util.GregorianCalendar classes are introduced in Chapter 11. Analyze the following code.

1. import java.util.*;

2. public class Test {

3. public static void main(String[] args) {

4. Calendar[] calendars = new Calendar[10];

5. calendars[0] = new Calendar();

6. calendars[1] = new GregorianCalendar();

7. }

8. }

单选题 (2 分) 2 分

  1.  A.

    The program has no compile errors.

  2.  B.

    The program has a compile error on Line 5 because java.util.Calendar is an abstract class.

  3.  C.

    The program has a compile error on Line 4 because java.util.Calendar is an abstract class.

  4.  D.

    The program has a compile error on Line 6 because Calendar[1] is not of a GregorianCalendar type.

7.

Analyze the following code.

public class Test {

public static void main(String[] args) {

java.util.Date x = new java.util.Date();

java.util.Date y = x.clone();

System.out.println(x = y);

}

}

单选题 (2 分) 2 分

  1.  A.

    A java.util.Date object is not cloneable.

  2.  B.

    x = y in System.out.println(x = y) causes a compile error because you cannot have an assignment statement inside a statement.

  3.  C.

    x = y in System.out.println(x = y) causes a runtime error because you cannot have an assignment statement inside a statement.

  4.  D.

    The program has a compile error because the return type of the clone() method is java.lang.Object.

13.

Assume Calendar calendar = new GregorianCalendar(). __________ returns the month of the year.

单选题 (2 分) 2 分

  1.  A.

    calendar.get(Calendar.WEEK_OF_MONTH)

  2.  B.

    calendar.get(Calendar.WEEK_OF_YEAR)

  3.  C.

    calendar.get(Calendar.MONTH)

  4.  D.

    calendar.get(Calendar.MONTH_OF_YEAR)

16.

Assume an employee can work for only one company. What is the best suitable relationship between Company and Employee?

单选题 (2 分) 2 分

  1.  A.

    Aggregation

  2.  B.

    Composition

  3.  C.

    None

  4.  D.

    Inheritance

17.

Analyze the following code.

1. public class Test {

2. public static void main(String[] args) {

3. Fruit[] fruits = {new Fruit(2), new Fruit(3), new Fruit(1)};

4. java.util.Arrays.sort(fruits);

5. }

6. }

class Fruit {

private double weight;

public Fruit(double weight) {

this.weight = weight;

}

}

 回答错误

单选题 (2 分) 0 分

  1.  A.

    The program has a compile error because the Fruit class does not have a no-arg constructor.

  2.  B.

    The program has a runtime error on Line 4 because the Fruit class does not implement the java.lang.Comparable interface and the Fruit objects are not comparable.

  3.  C.

    The program has a compile error on Line 4 because the Fruit class does not implement the java.lang.Comparable interface and the Fruit objects are not comparable.

  4.  D.

    The program has a runtime error on Line 3 because the Fruit class does not have a no-arg constructor.

22.

The Rational class in this chapter is defined as a subclass of java.lang.Number. Which of the following expressions is correct?

多选题 (2 分) 2 分

  1.  A.

    Rational.doubleValue();

  2.  B.

    new Rational(5, 4).intValue();

  3.  C.

    new Rational(5, 4).toDoubleValue();

  4.  D.

    new Rational(5, 4).doubleValue();

  5.  E.

    Rational.doubleValue("5/4");

24.

Which of the following statements are true?

多选题 (2 分) 2 分

  1.  A.

    The Date class implements Comparable.

  2.  B.

    The Double class implements Comparable.

  3.  C.

    The BigInteger class implements Comparable.

  4.  D.

    The String class implements Comparable.

25.

Which of the following statements are true?

多选题 (2 分) 2 分

  1.  A.

    A class should describe a single entity and all the class operations should logically fit together to support a coherent purpose.

  2.  B.

    The constructors may be protected.

  3.  C.

    The constructors must always be public.

  4.  D.

    A class should always contain a no-arg constructor.

26.

_______ is a reference type.

多选题 (2 分) 2 分

  1.  A.

    An array type

  2.  B.

    A class type

  3.  C.

    A primitive type

  4.  D.

    An interface type

28.

The GeometricObject and Circle classes are defined in this chapter. Analyze the following code.

public class Test {

public static void main(String[] args) {

GeometricObject x = new Circle(3);

GeometricObject y = (Circle)(x.clone());

System.out.println(x);

System.out.println(y);

}

}

多选题 (2 分) 2 分

  1.  A.

    If GeometricObject implements Cloneable and Circle overrides the clone() method, the clone() method will work fine to clone Circle objects.

  2.  B.

    After you override the clone() method and make it public in the Circle class, the problem can compile and run just fine, but y is null if Circle does not implement the Cloneable interface.

  3.  C.

    The program has a compile error because the clone() method is protected in the Object class.

  4.  D.

    To enable a Circle object to be cloned, the Circle class has to override the clone() method and implement the java.lang.Cloneable interface.

30.

Analyze the following code:

public class Test1 {

public Object max(Object o1, Object o2) {

if ((Comparable)o1.compareTo(o2) >= 0) {

return o1;

}

else {

return o2;

}

}

}

 回答错误

多选题 (2 分) 0 分

  1.  A.

    The program has a compile error because Test1 does not have a main method.

  2.  B.

    The program has a compile error because o1 is an Object instance and it does not have the compareTo method.

  3.  C.

    The program has a compile error because you cannot cast an Object instance o1 into Comparable.

  4.  D.

    The program would compile if ((Comparable)o1.compareTo(o2) >= 0) is replaced by (((Comparable)o1).compareTo(o2) >= 0).

32.

Which of the following statements are correct?

多选题 (2 分) 2 分

  1.  A.

    Number i = 4.5;

  2.  B.

    Integer i = 4.5;

  3.  C.

    Double i = 4.5;

  4.  D.

    Object i = 4.5;

34.

Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a no-arg constructor. Which of the following is correct?

多选题 (2 分) 2 分

  1.  A.

    B b = new B();

  2.  B.

    A a = new B();

  3.  C.

    A a = new A();

  4.  D.

    B b = new A();

35.

Which of the following is incorrect?

多选题 (2 分) 2 分

  1.  A.

    An interface may contain constructors.

  2.  B.

    The constructors in an abstract class are private.

  3.  C.

    You may declare a final abstract class.

  4.  D.

    The constructors in an abstract class should be protected.

  5.  E.

    An abstract class contains constructors.

36.

Which of the following is poor design?

多选题 (2 分) 2 分

  1.  A.

    A data field is derived from other data fields in the same class.

  2.  B.

    A method is an instance method, but it does not reference any instance data fields or invoke instance methods.

  3.  C.

    A parameter is passed from a constructor to initialize a static data field.

  4.  D.

    A method must be invoked after/before invoking another method in the same class.

39.

An interface can extend any number of interfaces using the implements keyword.

 回答错误

判断题 (2 分) 0 分

  1.  A.

    false

  2.  B.

    true

49.

All the numeric wrapper classes implement the Comparable interface.

判断题 (2 分) 2 分

  1.  A.

    true

  2.  B.

    false

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值