栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/606675.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号