Deck 8: Advanced Method Concepts

Full screen (f)
exit full mode
Question
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.
Use Space or
up arrow
down arrow
to flip the card.
Question
A method can return at most one value to a method that calls it.
Question
____ involves the ability to write multiple versions of a method using the same method name.

A) Overloading
B) Interfacing
C) Inheriting
D) Implementation hiding
Question
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
Question
You use the keyword ____ as a modifier to indicate an output parameter.

A) ref
B) params
C) get
D) out
Question
Only one ____ keyword is permitted in a method declaration.

A) ref
B) params
C) out
D) string
Question
____ 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
Question
You cannot use the out or ref keywords when passing an array to a method.
Question
When you use a reference parameter, any passed variable must have an assigned value.
Question
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
Question
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
Question
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()
Question
In C#, parameters can be mandatory or ____.

A) optional
B) reference
C) output
D) value
Question
Overloaded methods sharing the same identifier must have the same return type.
Question
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
Question
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
Question
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
Question
A method's name and parameter list constitute the method's ____.

A) return type
B) stamp
C) signature
D) type
Question
Methods with identical names that have identical parameter lists but different return types are ____ methods.

A) applicable
B) illegal
C) overloaded
D) related
Question
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
Question
What is the difference between a reference parameter and an output parameter?
Question
What is programming principle is violated when using named arguments and why is this important?
Question
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
Question
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 ");
}
}
Question
The rules that determine which method version to call are known as ____________________.
Question
What are the four types of mandatory parameters supported by C#?
Question
In C#, all data types are ____________________.
Question
What are two options for writing a called method that results in altering a single value in the calling method?
Question
Unnamed method arguments are also known as ____ arguments.

A) self-documenting
B) optional
C) default
D) positional
Question
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.
Question
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.
Question
Describe the similarities and differences among method versions when the method is overloaded.
Question
When a method call could execute multiple overloaded method versions, C# determines which method to execute using a process called ____________________.
Question
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);
}
}
Question
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
Question
Only ____ parameters can be given default values.

A) value
B) reference
C) output
D) array
Question
Omitted ____ arguments are ignored for betterness purposes on argument conversions.

A) default
B) explicit
C) local
D) optional
Question
When an int is promoted to a double , the process is called an implicit ____________________ or implicit cast.
Question
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
Question
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);
}
}
Question
Match between columns
A parameter that receives a copy of the value passed to it
self-documentation
A parameter that receives a copy of the value passed to it
ref modifier
A parameter that receives a copy of the value passed to it
value parameter
A parameter that receives a copy of the value passed to it
applicable methods
A parameter that receives a copy of the value passed to it
actual parameter
A parameter that receives a copy of the value passed to it
formal parameter
A parameter that receives a copy of the value passed to it
output parameter
A parameter that receives a copy of the value passed to it
parameter array
A parameter that receives a copy of the value passed to it
implementation hiding
An argument in a calling method
self-documentation
An argument in a calling method
ref modifier
An argument in a calling method
value parameter
An argument in a calling method
applicable methods
An argument in a calling method
actual parameter
An argument in a calling method
formal parameter
An argument in a calling method
output parameter
An argument in a calling method
parameter array
An argument in a calling method
implementation hiding
Named parameters can support this programming principle by providing clarity about the intended use of an argument
self-documentation
Named parameters can support this programming principle by providing clarity about the intended use of an argument
ref modifier
Named parameters can support this programming principle by providing clarity about the intended use of an argument
value parameter
Named parameters can support this programming principle by providing clarity about the intended use of an argument
applicable methods
Named parameters can support this programming principle by providing clarity about the intended use of an argument
actual parameter
Named parameters can support this programming principle by providing clarity about the intended use of an argument
formal parameter
Named parameters can support this programming principle by providing clarity about the intended use of an argument
output parameter
Named parameters can support this programming principle by providing clarity about the intended use of an argument
parameter array
Named parameters can support this programming principle by providing clarity about the intended use of an argument
implementation hiding
Declares a reference parameter
self-documentation
Declares a reference parameter
ref modifier
Declares a reference parameter
value parameter
Declares a reference parameter
applicable methods
Declares a reference parameter
actual parameter
Declares a reference parameter
formal parameter
Declares a reference parameter
output parameter
Declares a reference parameter
parameter array
Declares a reference parameter
implementation hiding
A programming principle compromised by named arguments
self-documentation
A programming principle compromised by named arguments
ref modifier
A programming principle compromised by named arguments
value parameter
A programming principle compromised by named arguments
applicable methods
A programming principle compromised by named arguments
actual parameter
A programming principle compromised by named arguments
formal parameter
A programming principle compromised by named arguments
output parameter
A programming principle compromised by named arguments
parameter array
A programming principle compromised by named arguments
implementation hiding
A parameter in a method header
self-documentation
A parameter in a method header
ref modifier
A parameter in a method header
value parameter
A parameter in a method header
applicable methods
A parameter in a method header
actual parameter
A parameter in a method header
formal parameter
A parameter in a method header
output parameter
A parameter in a method header
parameter array
A parameter in a method header
implementation hiding
A local array declared within the method header by using the keyword params
self-documentation
A local array declared within the method header by using the keyword params
ref modifier
A local array declared within the method header by using the keyword params
value parameter
A local array declared within the method header by using the keyword params
applicable methods
A local array declared within the method header by using the keyword params
actual parameter
A local array declared within the method header by using the keyword params
formal parameter
A local array declared within the method header by using the keyword params
output parameter
A local array declared within the method header by using the keyword params
parameter array
A local array declared within the method header by using the keyword params
implementation hiding
A set of methods that can accept a call given the passed argument list
self-documentation
A set of methods that can accept a call given the passed argument list
ref modifier
A set of methods that can accept a call given the passed argument list
value parameter
A set of methods that can accept a call given the passed argument list
applicable methods
A set of methods that can accept a call given the passed argument list
actual parameter
A set of methods that can accept a call given the passed argument list
formal parameter
A set of methods that can accept a call given the passed argument list
output parameter
A set of methods that can accept a call given the passed argument list
parameter array
A set of methods that can accept a call given the passed argument list
implementation hiding
Convenient when a variable might not have an assigned value when passed to a method
self-documentation
Convenient when a variable might not have an assigned value when passed to a method
ref modifier
Convenient when a variable might not have an assigned value when passed to a method
value parameter
Convenient when a variable might not have an assigned value when passed to a method
applicable methods
Convenient when a variable might not have an assigned value when passed to a method
actual parameter
Convenient when a variable might not have an assigned value when passed to a method
formal parameter
Convenient when a variable might not have an assigned value when passed to a method
output parameter
Convenient when a variable might not have an assigned value when passed to a method
parameter array
Convenient when a variable might not have an assigned value when passed to a method
implementation hiding
Question
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')
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/42
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
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
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
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
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
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
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
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
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()
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
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
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
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
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
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
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
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
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 ");
}
}
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
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.
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);
}
}
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
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
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
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
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);
}
}
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
A parameter that receives a copy of the value passed to it
self-documentation
A parameter that receives a copy of the value passed to it
ref modifier
A parameter that receives a copy of the value passed to it
value parameter
A parameter that receives a copy of the value passed to it
applicable methods
A parameter that receives a copy of the value passed to it
actual parameter
A parameter that receives a copy of the value passed to it
formal parameter
A parameter that receives a copy of the value passed to it
output parameter
A parameter that receives a copy of the value passed to it
parameter array
A parameter that receives a copy of the value passed to it
implementation hiding
An argument in a calling method
self-documentation
An argument in a calling method
ref modifier
An argument in a calling method
value parameter
An argument in a calling method
applicable methods
An argument in a calling method
actual parameter
An argument in a calling method
formal parameter
An argument in a calling method
output parameter
An argument in a calling method
parameter array
An argument in a calling method
implementation hiding
Named parameters can support this programming principle by providing clarity about the intended use of an argument
self-documentation
Named parameters can support this programming principle by providing clarity about the intended use of an argument
ref modifier
Named parameters can support this programming principle by providing clarity about the intended use of an argument
value parameter
Named parameters can support this programming principle by providing clarity about the intended use of an argument
applicable methods
Named parameters can support this programming principle by providing clarity about the intended use of an argument
actual parameter
Named parameters can support this programming principle by providing clarity about the intended use of an argument
formal parameter
Named parameters can support this programming principle by providing clarity about the intended use of an argument
output parameter
Named parameters can support this programming principle by providing clarity about the intended use of an argument
parameter array
Named parameters can support this programming principle by providing clarity about the intended use of an argument
implementation hiding
Declares a reference parameter
self-documentation
Declares a reference parameter
ref modifier
Declares a reference parameter
value parameter
Declares a reference parameter
applicable methods
Declares a reference parameter
actual parameter
Declares a reference parameter
formal parameter
Declares a reference parameter
output parameter
Declares a reference parameter
parameter array
Declares a reference parameter
implementation hiding
A programming principle compromised by named arguments
self-documentation
A programming principle compromised by named arguments
ref modifier
A programming principle compromised by named arguments
value parameter
A programming principle compromised by named arguments
applicable methods
A programming principle compromised by named arguments
actual parameter
A programming principle compromised by named arguments
formal parameter
A programming principle compromised by named arguments
output parameter
A programming principle compromised by named arguments
parameter array
A programming principle compromised by named arguments
implementation hiding
A parameter in a method header
self-documentation
A parameter in a method header
ref modifier
A parameter in a method header
value parameter
A parameter in a method header
applicable methods
A parameter in a method header
actual parameter
A parameter in a method header
formal parameter
A parameter in a method header
output parameter
A parameter in a method header
parameter array
A parameter in a method header
implementation hiding
A local array declared within the method header by using the keyword params
self-documentation
A local array declared within the method header by using the keyword params
ref modifier
A local array declared within the method header by using the keyword params
value parameter
A local array declared within the method header by using the keyword params
applicable methods
A local array declared within the method header by using the keyword params
actual parameter
A local array declared within the method header by using the keyword params
formal parameter
A local array declared within the method header by using the keyword params
output parameter
A local array declared within the method header by using the keyword params
parameter array
A local array declared within the method header by using the keyword params
implementation hiding
A set of methods that can accept a call given the passed argument list
self-documentation
A set of methods that can accept a call given the passed argument list
ref modifier
A set of methods that can accept a call given the passed argument list
value parameter
A set of methods that can accept a call given the passed argument list
applicable methods
A set of methods that can accept a call given the passed argument list
actual parameter
A set of methods that can accept a call given the passed argument list
formal parameter
A set of methods that can accept a call given the passed argument list
output parameter
A set of methods that can accept a call given the passed argument list
parameter array
A set of methods that can accept a call given the passed argument list
implementation hiding
Convenient when a variable might not have an assigned value when passed to a method
self-documentation
Convenient when a variable might not have an assigned value when passed to a method
ref modifier
Convenient when a variable might not have an assigned value when passed to a method
value parameter
Convenient when a variable might not have an assigned value when passed to a method
applicable methods
Convenient when a variable might not have an assigned value when passed to a method
actual parameter
Convenient when a variable might not have an assigned value when passed to a method
formal parameter
Convenient when a variable might not have an assigned value when passed to a method
output parameter
Convenient when a variable might not have an assigned value when passed to a method
parameter array
Convenient when a variable might not have an assigned value when passed to a method
implementation hiding
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')
Unlock Deck
Unlock for access to all 42 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 42 flashcards in this deck.