类和对象的基本使用

成绩: 70.0分

一、单选题 (题数:32,共 80.0 分)
14.1 Q1: Which of the following statements is true?(2.5分)0.0 分
A、
Constructors can specify parameters and return types.
B、
Constructors can specify parameters but not return types.
C、
Constructors cannot specify parameters but can specify return types.
D、
Constructors can specify neither parameters nor return types.
正确答案: B 我的答案:A
25.2 Q2: The format specifier %.2f specifies that two digits of precision should be output ________ in the floating-point number.(2.5分)2.5 分
A、
to the left of the decimal point
B、
centered
C、
to the right of the decimal point
D、
None of the above.
正确答案: C 我的答案:C
34.2 Q2: Which of the following statements is false?(2.5分)2.5 分
A、
If a class does not define constructors, the compiler provides a default constructor with no parameters.
B、
If you declare a constructor for a class, the compiler will not create a default constructor for that class.
C、
The UML models constructors in the third compartment of a class diagram.
D、
To distinguish a constructor from a class’s operations, the UML places the word constructor between double quotes before the constructor’s name.
正确答案: D 我的答案:D
44 Q1: Java requires a ________ call for every object that’s created.(2.5分)2.5 分
A、
constructor
B、
destructor
C、
parameterless
D、
parameterized
正确答案: A 我的答案:A
52.4 Q1: Which of the following statements is false?(2.5分)2.5 分
A、
In the UML, each class is modeled in a class diagram as a rectangle with three compartments. The top one contains the class’s name centered horizontally in boldface. The middle one contains the class’s attributes, which correspond to instance variables in Java. The bottom one contains the class’s operations, which correspond to methods and constructors in Java.
B、
UML represents instance variables as an attribute name, followed by a colon and the type.
C、
Private attributes are preceded by the keyword private in the UML.
D、
The UML models operations by listing the operation name followed by a set of parentheses. A plus sign (+) in front of the operation name indicates that the operation is a public.
正确答案: C 我的答案:C
65.2 Q1: The format specifier ________ is used to output values of type float or double.(2.5分)2.5 分
A、
%f
B、
%d
C、
%fd
D、
%r
正确答案: A 我的答案:A
72.1 Q3: Which of the following statements is true?(2.5分)0.0 分
A、
Each object (instance) of the class shares the class’s instance variables.
B、
Most instance-variable declarations are preceded with the keyword public, which is an access modifier.
C、
Variables or methods declared with access modifier private are accessible only to methods of the class in which they’re declared.
D、
None of the above is true.
正确答案: C 我的答案:B
82.5 Q2: Which of the following statements is false?(2.5分)0.0 分
A、
Most classes you’ll use in Java programs must be imported explicitly.
B、
There’s a special relationship between classes that are compiled in the same directory. By default, such classes are considered to be in the same package—known as the default package.
C、
Classes in the same package are implicitly imported into main.
D、
An import declaration is not required when one class in a package uses another in the same package.
正确答案: C 我的答案:D
92.2 Q3: Which of the following statements is true?(2.5分)2.5 分
A、
Local variables are automatically initialized.
B、
Every instance variable has a default initial value—a value provided by Java when you do not specify the instance variable’s initial value.
C、
The default value for an instance variable of type String is void.
D、
The argument types in the method call must be identical to the types of the corresponding parameters in the method’s declaration.
正确答案: B 我的答案:B
102.4 Q2: Which of the following statements is true?(2.5分)0.0 分
A、
The UML models a parameter of an operation by listing the parameter name, followed by a colon and the parameter value between the parentheses after the operation name.
B、
The UML indicates an operation’s return type by placing a colon and the return value after the parentheses following the operation name.
C、
UML class diagrams do not specify return types for operations that do not return values.
D、
Declaring instance variables public is known as data hiding or information hiding.
正确答案: C 我的答案:B
112.5 Q4: An import declaration is not required if you always refer to a class with its ________ name, which includes its package name and class name.(2.5分)2.5 分
A、
compile-time
B、
default package
C、
paired
D、
fully qualified name
正确答案: D 我的答案:D
122.3 Q1: Which of the following statements is false?(2.5分)0.0 分
A、
The javac command can compile multiple classes at once; simply list the source-code filenames after the command with each filename separated by a comma from the next.
B、
If the directory containing the app includes only one app’s files, you can compile all of its classes with the command javac .java.
C、
The asterisk (
) in javac *.java indicates that all files in the current directory ending with the filename extension .java should be compiled.
D、
All of the above are true.
正确答案: A 我的答案:C
132.1 Q4: When a method terminates, the values of its local variables are ________.(2.5分)2.5 分
A、
saved
B、
copied
C、
restored
D、
lost
正确答案: D 我的答案:D
142.2 Q1: A class that creates an object of another class, then calls the object’s methods, is called a(n) ________ class.(2.5分)2.5 分
A、
object-oriented
B、
inherited
C、
caller
D、
driver.
正确答案: D 我的答案:D
152 Q1: Each class you create becomes a new ________ that can be used to declare variables and create objects.(2.5分)2.5 分
A、
package
B、
instance
C、
library
D、
type.
正确答案: D 我的答案:D
162.1 Q1: Which of the following statements is false?(2.5分)2.5 分
A、
Each class declaration that begins with the access modifier private must be stored in a file that has the same name as the class and ends with the .java filename extension.
B、
Every class declaration contains keyword class followed immediately by the class’s name.
C、
Class, method and variable names are identifiers.
D、
An object has attributes that are implemented as instance variables and carried with it throughout its lifetime.
正确答案: A 我的答案:A
172.1 Q5: Which of the following statements is false?(2.5分)2.5 分
A、
Variables declared in the body of a particular method are local variables and can be used only in that method.
B、
A method’s parameters are local variables of the method.
C、
Every method’s body is delimited by left and right braces ({ and }).
D、
Keyword null indicates that a method will perform a task but will not return any information.
正确答案: D 我的答案:D
182.2 Q2: Which of the following statements is false?(2.5分)2.5 分
A、
Scanner method next reads characters until any white-space character is encountered, then returns the characters as a String.
B、
To call a method of an object, follow the object name with a comma, the method name and a set of parentheses containing the method’s arguments.
C、
A class instance creation expression begins with keyword new and creates a new object.
D、
A constructor is similar to a method but is called implicitly by the new operator to initialize an object’s instance variables at the time the object is created.
正确答案: B 我的答案:B
195.1 Q1: A __________ of a class called myClass is another class whose methods call the methods of myClass.(2.5分)0.0 分
A、
consumer
B、
servant
C、
caller
D、
client
正确答案: D 我的答案:C
202.6 Q1: Declaring instance variables ________ is known as data hiding or information hiding.(2.5分)2.5 分
A、
secure
B、
private
C、
static
D、
masked
正确答案: B 我的答案:B
214.2 Q1: If a class does not define constructors, the compiler provides a default constructor with no parameters, and the class’s instance variables are initialized to ________.(2.5分)2.5 分
A、
zero
B、
null
C、
their default values.
D、
false
正确答案: C 我的答案:C
22
3.3 Q1: Which of the following statements is false?

(2.5分)2.5 分
A、
A floating-point number is a number with a decimal point.

B、
Java provides two primitive types for storing floating-point numbers in memory—float and double.

C、
Variables of type float represent single-precision floating-point numbers and have seven significant digits.

D、
Variables of type float represent double-precision floating-point numbers; these require twice as much memory as double variables.

正确答案: D 我的答案:D
232.1 Q6: Which of the following statements is false?(2.5分)0.0 分
A、
The method’s return type specifies the type of data returned to a method’s caller.
B、
Empty parentheses following a method name indicate that the method does not require any parameters to perform its task.
C、
When a method that specifies a return type other than void is called and completes its task, the method must return a result to its calling method
D、
Classes often provide public methods to allow the class’s clients to set or get private instance variables; the names of these methods must begin with set or get.
正确答案: D 我的答案:C
242.1 Q2: Which of the following statements is false?(2.5分)0.0 分
A、
By convention class names begin with an uppercase letter, and method and variable names begin with a lowercase letter.
B、
Instance variables exist before methods are called on an object, while the methods are executing and after the methods complete execution.
C、
A class normally contains one or more methods that manipulate the instance variables that belong to particular objects of the class.
D、
Instance variables can be declared anywhere inside a class.
正确答案: D 我的答案:B
253.4 Q2: Which of the following is not a control structure:(2.5分)0.0 分
A、
Sequence structure.
B、
Selection structure.
C、
Repetition structure.
D、
Declaration structure.
正确答案: D 我的答案:A
答案解析:

26
3.11 Q1: Which of the following code segments does not increment val by 3:

(2.5分)2.5 分
A、
val += 3;

B、
{val = val + 1;
val = val + 1;
val = val + 1;}

C、
{c = 3;
val = val + (c == 3 ? 2 : 3);}

扫描二维码关注公众号,回复: 10345197 查看本文章

D、
All of the above increment val by 3.

正确答案: C 我的答案:C
273.13 Q3: Which primitive type can hold the largest value?(2.5分)2.5 分
A、
int
B、
long
C、
float
D、
double
正确答案: D 我的答案:D
答案解析:

28
Q1:{ Which of the following for-loop headers results in equivalent numbers of iterations:

A. for (int q = 1; q <= 100; q++)

B. for (int q = 100; q >= 0; q–)

C. for (int q = 99; q > 0; q -= 9)

D. for (int q = 990; q > 0; q -= 90)

(2.5分)2.5 分
A、
A and B

B、
C and D

C、
A and B have equivalent iterations and C and D have equivalent iterations.

D、
None of the loops have equivalent iterations.

正确答案: B 我的答案:B
29
Q2: What is output by the following Java code segment?

int temp = 180;

if (temp > 90)

{

System.out.println(“This porridge is too hot.”);

// cool down

temp = temp – (temp > 150 ? 100 : 20);

}

else

{

if (temp < 70)

{

  System.out.println("This porridge is too cold.");

 

  // warm up

  temp = temp + (temp < 50 ? 30 : 20);

}

}

if (temp == 80)

System.out.println(“This porridge is just right!”);

}

(2.5分)2.5 分
A、
This porridge is too hot.

B、
{This porridge is too cold.
This porridge is just right! }

C、
This porridge is just right!

D、
None of the above.

正确答案: D 我的答案:D
304.9 Q2: Which of the following is not a type of repetition statement in Java?(2.5分)2.5 分
A、
while statement.
B、
do…while statement.
C、
for statement.
D、
loop statement.
正确答案: D 我的答案:D
答案解析:

313.6 Q5: Which of the following statements is true?(2.5分)2.5 分
A、
Both syntax errors and logic errors are caught by the compiler.
B、
Both syntax errors and logic errors have effects at execution time.
C、
Syntax errors are caught by the compiler. Logic errors have effects at execution time.
D、
Logic errors are caught by the compiler. Syntax errors have effects at execution time.
正确答案: C 我的答案:C
答案解析:

324.8 Q2: {Suppose variable gender contains MALE and age equals 60, how is the expression
(gender == FEMALE) && (age >= 65)
evaluated?
}(2.5分)0.0 分
A、
The condition (gender == FEMALE) is evaluated first and the evaluation stops immediately.
B、
The condition (age >= 65) is evaluated first and the evaluation stops immediately.
C、
Both conditions are evaluated, from left to right.
D、
Both conditions are evaluated, from right to left.
正确答案: A 我的答案:C
答案解析:

二、填空题 (题数:8,共 20.0 分)
1
Each class declaration that begins with keyword must be stored in a file that has exactly the same name as the class and ends with the .java filename extension.

(2.5分)2.5 分
正确答案

第一空:
public

我的答案:

第一空:
public

答案解析:

2
Types in Java are divided into two categories— types and types.

(2.5分)2.5 分
正确答案

第一空:
primitive

第二空:
reference

我的答案:

第一空:
primitive

第二空:
reference

答案解析:

3

public class Account {

private      1     name;

public    2    setName(String n){

	this.name =    3    ;

}

public    4     getName(){

	return name;

}	

}

import java.util.Scanner;

public class AccountTest {

public static void main(String args[]) {

	Scanner    5    = new Scanner(   6    );

	Account ac1 = new Account();

            //display the name

	System.out.print(     7      );

	

	String sn = input.    8   ;

            //modify the name

                             9            

	System.out.print(   10       );				

}	

}

(2.5分)2.5 分
正确答案

第一空:
String

第二空:
void

第三空:
n

第四空:
String

第五空:
input

第六空:
System.in

第七空:
ac1.getName();

第八空:
nextLine()

第九空:
ac1.setName(sn);

第十空:
ac1.getName()

我的答案:

第一空: String
第二空: void
第三空: n
第四空: String
第五空: input
第六空: System.in
第七空: ac1.getName()
第八空: nextLine()
第九空: ac1.setName(sn);
第十空: ac1.getName()
4
Keyword in a class declaration is followed immediately by the class’s name.

(2.5分)0.0 分
正确答案

第一空:
class

我的答案:

第一空: public
答案解析:

5
Java provides two primitive types for storing floating-point numbers in memory: and .

(2.5分)2.5 分
正确答案

第一空:
float

第二空:
double

我的答案:

第一空: float
第二空: double
答案解析:

6
Return type indicates that a method will not return a value.

(2.5分)2.5 分
正确答案

第一空:
void

我的答案:

第一空: void
答案解析:

7
The format specifier is used to output values of type float or double.

(2.5分)2.5 分
正确答案

第一空:
%f

我的答案:

第一空: %f
答案解析:

8
Scanner method reads characters until it encounters a newline character, then returns those characters as a String.

(2.5分)0.0 分
正确答案

第一空:
nextLine()

我的答案:

第一空: nextString
答案解析:

发布了4 篇原创文章 · 获赞 1 · 访问量 16

猜你喜欢

转载自blog.csdn.net/lalalaAuraro/article/details/105224367
今日推荐