Ch. 7 Flashcards
(20 cards)
It’s always better to write your own code than to search and use a class from the FCL.
True.
False.
False
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, B, C, D
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.
False
Since memory in a computer is finite, a stack error may occur known as stack overflow.
True.
False.
True
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
All these four methods are overloaded
Information may be _________ methods.
passed to
returned from
manipulated in
All of the above.
All of the above.
Any variables declared in a for statement header have block scope within that statement.
True.
False.
True
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.
the field is “hidden” until the method is finished executing
What is the default value of a reference?
0
“”
null
default
null
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.
Math.Sqrt(36);
Methods that call themselves are known as ________ methods.
reiterative
self-calling
repeat-calling
recursive
recursive
Values produced by random-number generating methods are truly random. There is no way to predict the next result.
True.
False.
False
Any variable declared with keyword const is a constant and cannot be changed after it’s declared and initialized.
True.
False.
True
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”;
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.
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.
It begins at the identifier’s declaration and ends at the terminating right brace (}).
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.
Methods with the same signatures but different return types.
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.
True
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.
None of the above.
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 variable with one copy shared by all class objects
A static variable represents class-wide information.
True.
False.
True