Ch. 7 Flashcards

(20 cards)

1
Q

It’s always better to write your own code than to search and use a class from the FCL.
True.
False.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A C# class can have which of the following methods?
A: void foo(int a)
B: void foo(int a, int b)
C: void foo(double a)
D: void foo(double a, double b)
E: void foo(int b)

All of the above.
A, B, D, E
A, B, C, D
A, C, D, E

A

A, B, C, D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

If a change is made to an underlying value in an enumeration, you must change the program in every place that the old value was used.
True.
False.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Since memory in a computer is finite, a stack error may occur known as stack overflow.
True.
False.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which of the following methods are overloaded?
A: public int max (int a, int b) { … }
B: public double max (double a, double b) { … }
C: public int max (int a, int b, int c) { … }
D: public double max (double a, double b, double c) { … }

A and B are overloaded; C and D are overloaded

A and C are overloaded; B and D are overloaded

A, B and C are overloaded

All these four methods are overloaded

A

All these four methods are overloaded

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Information may be _________ methods.
passed to
returned from
manipulated in
All of the above.

A

All of the above.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Any variables declared in a for statement header have block scope within that statement.
True.
False.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

If a local variable in a method has the same name as a field of the method’s class, what will occur?

an error is generated

the field is “hidden” until the method is finished executing

the field will override the variable from the method

None of the above.

A

the field is “hidden” until the method is finished executing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the default value of a reference?
0
“”
null
default

A

null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following correctly calls the Math class method Sqrt with a value of 36?
Sqrt(36);
Math.Sqrt(36);
Math.Sqrt = 36;
None of the above.

A

Math.Sqrt(36);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Methods that call themselves are known as ________ methods.
reiterative
self-calling
repeat-calling
recursive

A

recursive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Values produced by random-number generating methods are truly random. There is no way to predict the next result.
True.
False.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Any variable declared with keyword const is a constant and cannot be changed after it’s declared and initialized.
True.
False.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Consider the following Cube method:
static int Cube(int x)
{
return x * x * x;
}
Which of the following statements is false?

In C# 6, this method can be defined with an expression-bodied method as: static int Cube(int x) => x * x * x; The value of x * x * x is returned to Cube’s caller implicitly.

The symbol => follows the method’s parameter list and introduces the method’s body-no braces or return statement are required. This can be used only with static methods.

If the expression to the right of => does not have a value (e.g., a call to a method that returns void), the expression-bodied method must return void.

Similarly, a read-only property can be implemented as an expression-bodied property. The following re-implements the IsNoFaultState property we used in the textbook to return the result of a logical expression: public bool IsNoFaultState => State == “MA” || State == “NJ” || State == “NY” || State == “PA”;

A

The symbol => follows the method’s parameter list and introduces the method’s body-no braces or return statement are required. This can be used only with static methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which of the following statements describes block scope?

It begins at the opening { of the class declaration and terminates at the closing }

It limits label scope to only the method in which it is declared.

It begins at the identifier’s declaration and ends at the terminating right brace (}).

It is valid for one statement only.

A

It begins at the identifier’s declaration and ends at the terminating right brace (}).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which of the following will violate the rules of overloading methods?

Methods with the same signatures but different return types.

Methods with different signatures but the same return type.

Methods with different number of arguments.

Method with different types of arguments.

A

Methods with the same signatures but different return types.

17
Q

A particular seed value passed to the Random class’s constructor causes the Random object to always produce the same series of random numbers.
True.
False.

18
Q

Which of the following is not part of recursion?
recursive call
recursion step(s)
a base case or multiple base cases
None of the above.

A

None of the above.

19
Q

Which of the following describes a static variable?

a variable with one copy shared by all class objects

a variable whose value may not be changed

all of the above

None of the above.

A

a variable with one copy shared by all class objects

20
Q

A static variable represents class-wide information.
True.
False.