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

1.

To obtain the distance between the points (40, 50) and (5.5, 4.4), use _________.

 回答错误

多选题 (2 分) 0 分

  1.  A.

    new Point2D(40, 50).distance(5.5, 4.4)

  2.  B.

    new Point2D(5.5, 4.4).distance(40, 50)

  3.  C.

    new Point2D(40, 50).distance(new Point2D(5.5, 4.4))

  4.  D.

    distance(40, 50, 5.5, 4.4)

  5.  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 分

  1.  A.

    an instance method

  2.  B.

    a static method or an instance method

  3.  C.

    a static method

4.

Which of the following statements are true?

多选题 (2 分) 2 分

  1.  A.

    Data fields have default values.

  2.  B.

    A variable of a reference type holds a reference to where an object is stored in the memory.

  3.  C.

    You may assign an int value to a reference variable.

  4.  D.

    Local variables do not have default values.

  5.  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 分

  1.  A.

    A method

  2.  B.

    An object

  3.  C.

    A data field

  4.  D.

    A class

6.

Variables that are shared by every instances of a class are __________.

单选题 (1 分) 1 分

  1.  A.

    instance variables

  2.  B.

    class variables

  3.  C.

    private variables

  4.  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 分

  1.  A.

    The program has a compile error because x has not been initialized.

  2.  B.

    The program has a runtime NullPointerException because test is null while executing test.x.

  3.  C.

    The program has a compile error because Test does not have a default constructor.

  4.  D.

    The program has a compile error because test is not initialized.

  5.  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 分

  1.  A.

    A private instance variable

  2.  B.

    A static variable

  3.  C.

    A local variable defined in any method

  4.  D.

    A public instance variable

24.

An immutable class cannot have _______.

 回答错误

单选题 (1 分) 0 分

  1.  A.

    no-arg constructors

  2.  B.

    private data fields

  3.  C.

    static data fields

  4.  D.

    public data fields

  5.  E.

    public constructors

30.

Which of the following statements are true about an immutable object?

 回答错误

多选题 (2 分) 0 分

  1.  A.

    An immutable object contains no mutator methods.

  2.  B.

    All properties of an immutable object must be private.

  3.  C.

    The contents of an immutable object cannot be modified.

  4.  D.

    All properties of an immutable object must be of primitive types.

  5.  E.

    An object type property in an immutable object must also be immutable.

35.

You cannot use the private modifier on classes.

判断题 (1 分) 1 分

  1.  A.

    false

  2.  B.

    true

44.

Java assigns a default value to a local variable in a method if the variable is not initialized.

 回答错误

判断题 (1 分) 0 分

  1.  A.

    false

  2.  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 分

  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.

  2.  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.

  3.  C.

    Since x is private, it cannot be accessed from an object foo.

  4.  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 分

  1.  A.

    The variable t is private and therefore cannot be accessed in the main method.

  2.  B.

    t is non-static and it cannot be referenced in a static context in the main method.

  3.  C.

    The program compiles and runs fine.

  4.  D.

    The variable x is not initialized and therefore causes errors.

  5.  E.

    The variable t is not initialized and therefore causes errors.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值