Java教程

自用 | bb选择题 assgn4

本文主要是介绍自用 | bb选择题 assgn4,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1. You can declare two variables with the same name in __________.

A. a block

B. different methods in a class

C. two nested blocks in a method (two nested blocks means one being inside the other)

D. a method one as a formal parameter and the other as a local variable

2. _______ is a construct that defines objects of the same type.

A. A data field

B. A class

C. An object

D. A method

3. You should add the static keyword in the place of ? in Line ________ in the following code:

1 public class Test {

2   private int age;

3

4   public ? int square(int n) {

5     return n * n;

6   }

7

8   public ? int getAge() {

9  }

10}

A.in line 4

4. Which of the following statements are true?

A. At least one constructor must always be defined explicitly.(必须始终明确定义至少一个构造函数)

B.The default constructor(默认构造函数) is a no-arg constructor(无参数构造函数).

C.A default constructor is provided automatically if no constructors are explicitly declared in the class.

D.Every class has a default constructor.

5. ___________ can be accessed from any instance method(实例变量) in the class.

A. A static variable(静态变量)

B. An instance variable(实例变量)

C.A local variable(局部变量)

实例方法可以操作类变量(static变量),也叫类的静态变量。

static方法不能操作实例变量。

原因很简单,实例变量(或实例方法)是要有类的实例才能访问的,即先要new一个对象,才能访问。而static方法或变量,不需要创建对象,直接通过类名访问,所以它不能访问实例变量。

6. You cannot use modifiers on local variables inside a method except final.

A. true

B. false

7. ________ is invoked to create an object.

A. The main method

B. A method with the void return type

C. A constructor

D. A method with a return type

8. You can access a class variable using a syntax like objectName.classVariable or ClassName.classVariable.

A. false

B. true

9. Which of the following statements are true?

A. You may assign an int value to a reference variable.

B.A variable of a primitive type holds a value of the primitive type.

C. Local variables do not have default values.

D. Data fields have default values.

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

错题:选了A

10. You can declare variables of the same name in a method if they are in non-nesting blocks.

A. false

B. true

11. You use the _________ operator to access members of an object.

A. .

B. *

C. ()

D. %

12. You cannot use the private modifier on classes.

A. false

B. true

13. You can always use the default constructor even though the non-default constructors are defined in the class.

A. false

B. true

14. You can declare variables of the same name in a method even though they are in the same block.

A. true

B. false

15. You use underline to denote static variables and methods.

A. true

B. false

16. You use the plus sign (+) to denote public data or methods.

A. false

B. true

17. Which of the following statements are true?

A. Encapsulating data fields helps prevent programming errors.

B. Encapsulating data fields makes the program short.

C. Use the private modifier to encapsulate data fields.

D. Encapsulating data fields makes the program easy to maintain.

18. ______represents an entity in the real world that can be distinctly identified.

A. A method

B. A data field

C. A class

D. An object

19. Which of the following statements are true?

A. Multiple constructors can be defined in a class.      

B. Constructors are invoked using the new operator when an object is created.

C. Constructors must have the same name as the class itself.

D. Constructors do not have a return type, not even void.

20. __________ can be accessed from any static method in the class.

A. A local variable

B. A static variable

C. An instance variable

这篇关于自用 | bb选择题 assgn4的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!