当前位置:   article > 正文

面向对象程序设计(Java) chapter13_what is the best suitable relationship between emp

what is the best suitable relationship between employee and faculty?

The java.lang.Number and its subclasses are introduced in Chapter 11. Analyze the following code.

Number numberRef = new Integer(0);

Double doubleRef = (Double)numberRef; 
  • 1
  • 2
  • 3

单选题 (2 分)
C
A.There is no such class named Integer. You should use the class Int.

B.You can convert an int to double, so you can cast an Integer instance to a Double instance.

C.A runtime class casting exception occurs(转换异常), since numberRef is not an instance of Double.

D.The compiler detects that numberRef is not an instance of Double.

E.The program runs fine, since Integer is a subclass of Double.
2.Which of the following class definitions defines a legal(合法的) abstract class(抽象类)?
单选题 (2 分)
D
A.class A { abstract void unfinished(); }

B.public class abstract A { abstract void unfinished(); }

C.class A { abstract void unfinished() { } }

D.abstract class A { abstract void unfinished(); }
3.The relationship between an interface(接口) and the class that implements(实现) it is
单选题 (2 分)
B
A.None

B.Inheritance(继承物,遗产)

C.Aggregation(聚合)

D.Composition(成分)
5.
Analyze the following code.

public class Test {

public static void main(String[] args) {

Number x = new Integer(3);

System.out.println(x.intValue());

System.out.println(x.compareTo(new Integer(4)));
  • 1
  • 2
  • 3
  • 4
  • 5

}

}
单选题 (2 分)
A
A.The program has a compile error because x does not have the compareTo method.

B.The program compiles and runs fine.

C.The program has a compile error because an Integer instance cannot be assigned to a Number variable.

D.The program has a compile error because intValue is an abstract method in Number.
6.What is the best suitable relationship between Employee and Faculty?
单选题 (2 分)
B
A.Aggregation

B.Inheritance

C.Composition

D.None.
7.
The printout from the following code is __________.

java.util.ArrayList list = new java.util.ArrayList();

list.add(“New York”);

java.util.ArrayList list1 = (java.util.ArrayList)(list.clone());

list.add(“Atlanta”);

list1.add(“Dallas”);

System.out.println(list1);
单选题 (2 分) (clone 克隆)
D
A.[New York, Atlanta]

B.[New York, Atlanta, Dallas]

C.[New York]

D.[New York, Dallas]
11.
Show the output of running the class Test in the following code lines:

interface A {

}

class C {

}

class B extends D implements A {

}

public class Test {

public static void main(String[] args) {

B b = new B();

if (b instanceof A)

  System.out.println("b is an instance of A");

if (b instanceof C)

  System.out.println("b is an instance of C");
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

}

}

class D extends C {

}
单选题 (2 分)
A
A.b is an instance of A followed by b is an instance of C.

B.b is an instance of C.

C.b is an instance of A.

D.Nothing.
12.
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];
    
    • 1
  5. calendars[0] = new Calendar();
    
    • 1
  6. calendars[1] = new GregorianCalendar();
    
    • 1
  7. }

  8. }
    单选题 (2 分)
    A
    A.The program has a compile error on Line 5 because java.util.Calendar is an abstract class.

B.The program has no compile errors.

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

D.The program has a compile error on Line 6 because Calendar[1] is not of a GregorianCalendar type.
13.Which of the following declares an abstract method in an abstract Java class?
单选题 (2 分)
D
A.public abstract method();

B.public void method() {}

C.public void abstract Method();

D.public abstract void method();

E.public abstract void method() {}
15.Which of the following is a correct interface?
单选题 (2 分)
B
A.abstract interface A { abstract void print() { };}

B.interface A { void print();}

C.interface A { void print() { }; }

D.abstract interface A { print(); }
16.
Analyze the following code.

Number[] numberArray = new Integer[2];

numberArray[0] = new Double(1.5); 
  • 1
  • 2
  • 3

单选题 (2 分)
B
A.Since each element of numberArray is of the Number type, you cannot assign a Double object to it.

B.At runtime, new Integer[2] is assigned to numberArray. This makes each element of numberArray an Integer object. So you cannot assign a Double object to it.

C.You cannot use Number as a data type since it is an abstract class.

D.Since each element of numberArray is of the Number type, you cannot assign an Integer object to it.
17.
Analyze the following code.

public class Test {

public static void main(String[] args) {

Number x = new Integer(3);

System.out.println(x.intValue());

System.out.println((Integer)x.compareTo(new Integer(4)));
  • 1
  • 2
  • 3
  • 4
  • 5

}

}
单选题 (2 分)
E
A.The program has a compile error because x cannot be cast into Integer.

B.The program has a compile error because intValue is an abstract method in Number.

C.The program has a compile error because an Integer instance cannot be assigned to a Number variable.

D.The program compiles and runs fine.

E.The program has a compile error because the member access operator (.) is executed before the casting operator.
18.Assume an employee can work for only one company. What is the best suitable relationship between Company and Employee?
单选题 (2 分)
D
A.Aggregation(聚合)

B.None

C.Inheritance(继承)

D.Composition(成分)
19.Assume Calendar calendar = new GregorianCalendar(). __________ returns the month of the year.
单选题 (2 分)
D
A.calendar.get(Calendar.MONTH_OF_YEAR)

B.calendar.get(Calendar.WEEK_OF_YEAR)

C.calendar.get(Calendar.WEEK_OF_MONTH)

D.calendar.get(Calendar.MONTH)
20.
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);
  • 1
  • 2
  • 3
  • 4
  • 5

}

}
单选题 (2 分)
C
A.x = y in System.out.println(x = y) causes a runtime error because you cannot have an assignment statement inside a statement.

B.A java.util.Date object is not cloneable.

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

D.x = y in System.out.println(x = y) causes a compile error because you cannot have an assignment statement inside a statement.
23.Which of the following is poor design?
多选题 (2 分)
ABCD
A.A method must be invoked(调用) after/before invoking another method in the same class.

B.A parameter(参数) is passed(传递) from a constructor(构造函数) to initialize(初始化) a static data field.

C.A method is an instance(实例) method, but it does not reference any instance data fields or invoke instance methods.

D.A data field is derived(派生) from other data fields in the same class.
24.Which of the following statements regarding abstract methods are true?
多选题 (2 分)
ABCE
A.A subclass of a non-abstract superclass can be abstract.

B.An abstract class can be used as a data type.

C.An abstract class can be extended.

D.An abstract class can have instances created using the constructor of the abstract class.

E.A subclass can override a concrete method in a superclass to declare it abstract.
25.Which of the following is incorrect?
多选题 (2 分)
ABE
A.You may declare a final abstract class.

B.The constructors in an abstract class are private.

C.An abstract class contains constructors.

D.The constructors in an abstract class should be protected.

E.An interface may contain constructors.
26.Which of the following statements are true?
多选题 (2 分)
ABC
A.If you compile an interface without errors, but with warnings, a .class file is created for the interface.

B.If you compile a class without errors but with warnings, a .class file is created.

C.If you compile an interface without errors, a .class file is created for the interface.

D.If you compile a class with errors, a .class file is created for the class.
27.Which of the following statements regarding abstract methods are true?
多选题 (2 分)
ABCE
A.It is possible to declare an abstract class that contains no abstract methods.

B.A class that contains abstract methods must be abstract.

C.Abstract classes have constructors.

D.A data field can be declared abstract.

E.An abstract method cannot be contained in a nonabstract class.
28.Which of the following statements are true?
多选题 (2 分)
ABCDE
A.A strong is-a relationship can be represented using class inheritance.
(可以使用类继承来表示强 is-a 关系)
B.Inheritance models the is-a relationship between two classes.
(继承对两个类之间的 is-a 关系建模)
C.A weak is-a relationship can be represented using interfaces.
(弱的 is-a 关系可以使用接口来表示)
D.A strong is-a relationship describes a direct inheritance relationship between two classes.
(强 is-a 关系描述了两个类之间的直接继承关系)
E.A weak is-a relationship describes that a class has certain properties.
(弱 is-a 关系描述了一个类具有某些属性)
29.Which of the following statements are true?
多选题 (2 分)
ABCD
A.The Date class implements Comparable.

B.The String class implements Comparable.

C.The Double class implements Comparable.

D.The BigInteger class implements Comparable.
30._______ is a reference type.
多选题 (2 分) 2
ABC
A.An interface type

B.An array type

C.A class type

D.A primitive(原始) type
31.The Rational class in this chapter is defined as a subclass of java.lang.Number. Which of the following expressions is correct?
多选题 (2 分)
AC
A.new Rational(5, 4).intValue();

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

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

D.Rational.doubleValue();

E.Rational.doubleValue(“5/4”);
32.
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);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

}

}
多选题 (2 分)
ABCD
A.The program has a compile error because the clone() method is protected in the Object class.

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.

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

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.
33.Which of the following statements are true?
多选题 (2 分)
CD
A.The constructors must always be public.

B.A class should always contain a no-arg constructor.

C.A class should describe a single(单一的) entity(实体) and all the class operations(操作) should logically(逻辑上) fit(结合) together to support a coherent(连贯的) purpose.

D.The constructors may be protected.
35.Which of the following statements are true about abstract classes.
多选题 (2 分)
ABCDE
A.An abstract class cannot be instantiated using the new operator.

B.A subclass can be abstract even if its superclass is concrete.

C.If a subclass of an abstract superclass does not implement all the abstract methods, the subclass must be declared abstract.

D.It is possible to declare an abstract class that contains no abstract methods.

E.An abstract method cannot be contained in a nonabstract class.
36.Which of the following statements are correct?
多选题 (2 分)
ACD
A.Object i = 4.5;

B.Integer i = 4.5;

C.Double i = 4.5;

D.Number i = 4.5;
37.
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;

}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

}

}
多选题 (2 分)
BC
A.The program has a compile error because you cannot cast an Object instance o1 into Comparable.

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

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

D.The program has a compile error because Test1 does not have a main method.
39.All the numeric wrapper classes implement the Comparable interface.
(所有数字包装类都实现了 Comparable 接口)
判断题 (2 分)
A
A.true

B.false
40.At least one method in an abstract class must be abstract.
判断题 (2 分)
A
A.false

B.true
42.A subclass cannot extend more than one class, but may implement any number of interfaces.
(一个子类不能扩展多个类,但可以实现任意数量的接口)
判断题 (2 分)
B
A.false

B.true
43.The Number class is an instance of Comparable.
(Number 类是 Comparable 的一个实例)
判断题 (2 分)
A
A.false

B.true
44.An interface can extend any number of interfaces using the implements keyword.
(一个接口可以使用 implements 关键字扩展任意数量的接口)
判断题 (2 分)
B
A.true

B.false
46.The name of abstract class and interface is in italic in the UML.
(抽象类和接口的名称在 UML 中是斜体的)
判断题 (2 分)
A
A.true

B.false
47.The methods parseInt, parseDouble, parseFloat, parseLong are in the classes Integer, Double, Float, and Long to convert a numeric string into an integer, double, float, or long.
(方法 parseInt、parseDouble、parseFloat、parseLong 位于 Integer、Double、Float 和 Long 类中,用于将数字字符串转换为整数、双精度、浮点或长整数)
判断题 (2 分)
A
A.true

B.false
49.The numeric wrapper classes are subclasses of Number.
(数字包装类是 Number 的子类)
判断题 (2 分)
B
A.false

B.true

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/176125
推荐阅读
相关标签
  

闽ICP备14008679号