Deck 8: Advanced Method Concepts
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Match between columns
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/42
Play
Full screen (f)
Deck 8: Advanced Method Concepts
1
To ensure that the original value of an argument passed to a method remains unchanged after returning from the method, you should use a reference parameter or an output parameter.
False
2
A method can return at most one value to a method that calls it.
True
3
____ involves the ability to write multiple versions of a method using the same method name.
A) Overloading
B) Interfacing
C) Inheriting
D) Implementation hiding
A) Overloading
B) Interfacing
C) Inheriting
D) Implementation hiding
A
4
When you use a(n) ____ parameter in a method header, you indicate the parameter's type and name, and the method receives a copy of the value passed to it.
A) reference
B) output
C) input
D) value
A) reference
B) output
C) input
D) value
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
5
You use the keyword ____ as a modifier to indicate an output parameter.
A) ref
B) params
C) get
D) out
A) ref
B) params
C) get
D) out
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
6
Only one ____ keyword is permitted in a method declaration.
A) ref
B) params
C) out
D) string
A) ref
B) params
C) out
D) string
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
7
____ parameters act as aliases, or pseudonyms, for the same memory location occupied by the original variable being passed to a method.
A) Interface
B) Pointer
C) Reference
D) Value
A) Interface
B) Pointer
C) Reference
D) Value
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
8
You cannot use the out or ref keywords when passing an array to a method.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
9
When you use a reference parameter, any passed variable must have an assigned value.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
10
A(n) ____ parameter to a method is one for which a value is automatically supplied if you do not explicitly send one as an argument.
A) actual
B) value
C) default
D) optional
A) actual
B) value
C) default
D) optional
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
11
On occasion, you might want a method to be able to alter a value you pass to it. In that case, you can use a(n) ____ parameter or an output parameter.
A) value
B) reference
C) optional
D) global
A) value
B) reference
C) optional
D) global
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
12
To avoid data conversion exceptions that occur when a value cannot be converted to an appropriate type, you can use a version of the C# ____ method with an out parameter.
A) Convert()
B) ReadLine()
C) TryParse()
D) Parse()
A) Convert()
B) ReadLine()
C) TryParse()
D) Parse()
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
13
In C#, parameters can be mandatory or ____.
A) optional
B) reference
C) output
D) value
A) optional
B) reference
C) output
D) value
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
14
Overloaded methods sharing the same identifier must have the same return type.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
15
When you don't know how many arguments you might eventually send to a method, you can declare a(n) ____.
A) value parameter
B) parameter array
C) reference parameter
D) output parameter
A) value parameter
B) parameter array
C) reference parameter
D) output parameter
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
16
Methods are ____ when there is the potential for a situation in which the compiler cannot determine which method to use.
A) overloaded
B) ambiguous
C) polymorphic
D) hidden
A) overloaded
B) ambiguous
C) polymorphic
D) hidden
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
17
Using a(n) ____ parameter is convenient when the variable to be passed does not have an assigned value at the time the method is called.
A) reference
B) value
C) mandatory
D) output
A) reference
B) value
C) mandatory
D) output
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
18
A method's name and parameter list constitute the method's ____.
A) return type
B) stamp
C) signature
D) type
A) return type
B) stamp
C) signature
D) type
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
19
Methods with identical names that have identical parameter lists but different return types are ____ methods.
A) applicable
B) illegal
C) overloaded
D) related
A) applicable
B) illegal
C) overloaded
D) related
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
20
When you use a(n) ____ parameter, the argument used to call the method must have an assigned value.
A) output
B) optional
C) reference
D) formal
A) output
B) optional
C) reference
D) formal
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
21
What is the difference between a reference parameter and an output parameter?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
22
What is programming principle is violated when using named arguments and why is this important?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
23
If you assign a default value to any variable in a method's parameter list, then all parameters to the right of that parameter must have ____ values.
A) explicit
B) implicit
C) local
D) default
A) explicit
B) implicit
C) local
D) default
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
24
Given the following code, describe a situation that would make the code ambiguous to the C# compiler:
using static System.Console;
public class AmbiguousMethods
{
static void Main()
{
int iNum = 20;
double dNum = 4.5;
SimpleMethod(iNum, dNum); // calls first version
SimpleMethod(dNum, iNum); // calls second version
SimpleMethod(iNum, iNum); // error! Call is ambiguous.
}
private static void SimpleMethod( int i, double d)
{
WriteLine("Method receives int and double");
}
private static void SimpleMethod( double d, int i)
{
WriteLine("Method receives double and int ");
}
}
using static System.Console;
public class AmbiguousMethods
{
static void Main()
{
int iNum = 20;
double dNum = 4.5;
SimpleMethod(iNum, dNum); // calls first version
SimpleMethod(dNum, iNum); // calls second version
SimpleMethod(iNum, iNum); // error! Call is ambiguous.
}
private static void SimpleMethod( int i, double d)
{
WriteLine("Method receives int and double");
}
private static void SimpleMethod( double d, int i)
{
WriteLine("Method receives double and int ");
}
}
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
25
The rules that determine which method version to call are known as ____________________.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
26
What are the four types of mandatory parameters supported by C#?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
27
In C#, all data types are ____________________.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
28
What are two options for writing a called method that results in altering a single value in the calling method?
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
29
Unnamed method arguments are also known as ____ arguments.
A) self-documenting
B) optional
C) default
D) positional
A) self-documenting
B) optional
C) default
D) positional
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
30
Suppose that you create overloaded method versions with the following declarations:
private static void MyMethod( double d)
private static void MyMethod( float f)
Would MyMethod() run if it is called with an integer argument? Describe how C# determines which, if either, method should run when MyMethod() is called.
private static void MyMethod( double d)
private static void MyMethod( float f)
Would MyMethod() run if it is called with an integer argument? Describe how C# determines which, if either, method should run when MyMethod() is called.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
31
When you use the Visual Studio ____________________ to create programs, the IntelliSense feature will allow you to discover built-in overloaded methods by displaying all versions of the method when you type in the method name and the parameter list opening parenthesis.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
32
Describe the similarities and differences among method versions when the method is overloaded.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
33
When a method call could execute multiple overloaded method versions, C# determines which method to execute using a process called ____________________.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
34
Given the following program, write the InputMethod() method. It should read two values from the user and assign them to the int variables first and second , which are then printed out in the code shown below.
using static System.Console;
class InputMethodDemo
{
static void Main()
{
int first, second;
InputMethod( out first, out second);
WriteLine("After InputMethod first is {0}"), first);
WriteLine("and second is {0}"), second);
}
}
using static System.Console;
class InputMethodDemo
{
static void Main()
{
int first, second;
InputMethod( out first, out second);
WriteLine("After InputMethod first is {0}"), first);
WriteLine("and second is {0}"), second);
}
}
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
35
You name an argument in a method call using its parameter name and a ____ before the value.
A) comma
B) dot
C) colon
D) semicolon
A) comma
B) dot
C) colon
D) semicolon
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
36
Only ____ parameters can be given default values.
A) value
B) reference
C) output
D) array
A) value
B) reference
C) output
D) array
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
37
Omitted ____ arguments are ignored for betterness purposes on argument conversions.
A) default
B) explicit
C) local
D) optional
A) default
B) explicit
C) local
D) optional
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
38
When an int is promoted to a double , the process is called an implicit ____________________ or implicit cast.
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
39
Any optional parameters in a parameter list must appear to the right of all ____ parameters in the list.
A) local
B) mandatory
C) default
D) global
A) local
B) mandatory
C) default
D) global
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
40
Write the DisplayStrings() method called in the code below using a parameter array declared in the method header. The method should write its arguments in a single line, followed by a newline. What will the output be after running Main() ?
using static System.Console;
class ParamsDemo
{
static void Main()
{
string[] names = {"Mark"), "Paulette"), "Carol"};
DisplayStrings("Ginger");
DisplayStrings("George"), "Maria"), "Thomas");
DisplayStrings(names);
}
}
using static System.Console;
class ParamsDemo
{
static void Main()
{
string[] names = {"Mark"), "Paulette"), "Carol"};
DisplayStrings("Ginger");
DisplayStrings("George"), "Maria"), "Thomas");
DisplayStrings(names);
}
}
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
42
Given the following two method signatures, explain the reasoning behind how the C# compiler determines which method version to invoke for the call MyMethod(12) :
private static void MyMethod( int a)
private static void MyMethod( int a, char b = 'B')
private static void MyMethod( int a)
private static void MyMethod( int a, char b = 'B')
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck