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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/39
Play
Full screen (f)
Deck 8: Advanced Method Concepts
1
What type of parameters act as aliases, or pseudonyms, for the same memory location occupied by the original variable being passed to a method?
A) interface parameters
B) pointer parameters
C) reference parameters
D) value parameters
A) interface parameters
B) pointer parameters
C) reference parameters
D) value parameters
C
2
You cannot use the out or ref keywords when passing an array to a method.
False
3
A method's name and parameter list both constitute what component of the method?
A) The return type for the method
B) The method stamp.
C) The method's signature.
D) The method's type.
A) The return type for the method
B) The method stamp.
C) The method's signature.
D) The method's type.
C
4
For the sake of convenience, what parameter type can be used when the variable to be passed does not have an assigned value at the time the method is called?
A) reference parameter
B) value parameter
C) mandatory parameter
D) output parameter
A) reference parameter
B) value parameter
C) mandatory parameter
D) output parameter
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
5
When you use a reference parameter, any passed variable must have an assigned value.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
6
In C#, what can be done to ensure that a parameter for a method is required in every method call?
A) The parameter can be specified as mandatory.
B) The parameter should be hard coded.
C) The parameter should be specified as a constant in the class.
D) The argument to the called method can be specified as static.
A) The parameter can be specified as mandatory.
B) The parameter should be hard coded.
C) The parameter should be specified as a constant in the class.
D) The argument to the called method can be specified as static.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
7
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.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
8
What is a method considered to be when there is a potential for a situation in which the compiler cannot determine what 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 39 flashcards in this deck.
Unlock Deck
k this deck
9
When declaring a method, how any params keywords are permitted?
A) Only as many as there will be arguments.
B) Only one params keyword is permitted.
C) Two, provided there is a nested method.
D) There is no limit to the use of the keyword.
A) Only as many as there will be arguments.
B) Only one params keyword is permitted.
C) Two, provided there is a nested method.
D) There is no limit to the use of the keyword.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
10
What modifier is used to indicate that a parameter is used for output?
A) ref
B) params
C) get
D) out
A) ref
B) params
C) get
D) out
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
11
What type of parameter to a method will have a value automatically supplied if you do not explicitly send one as an argument?
A) actual parameter
B) value parameter
C) default parameter
D) optional parameter
A) actual parameter
B) value parameter
C) default parameter
D) optional parameter
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
12
On occasion, you might want a method to be able to alter a value you pass to it.What type of parameter should you use in this case?
A) value parameter
B) reference parameter
C) optional parameter
D) global parameter
A) value parameter
B) reference parameter
C) optional parameter
D) global parameter
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
13
A method can return at most one value to a method that calls it.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
14
How can you avoid throwing an exception during data conversion when a value cannot be converted to an appropriate type?
A) You can use the Convert() method to force the conversion.
B) You can use the ReadLine() method to convert the data to a string.
C) You can use the TryParse() method to attempt conversion, or assign a 0 to the variable if it is not possible.
D) You can use the Parse() method, which may result in garbage being returned.
A) You can use the Convert() method to force the conversion.
B) You can use the ReadLine() method to convert the data to a string.
C) You can use the TryParse() method to attempt conversion, or assign a 0 to the variable if it is not possible.
D) You can use the Parse() method, which may result in garbage being returned.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
15
What technique allows for 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
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
16
What should you utilize when you don't know how many arguments you might eventually send to a method?
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 39 flashcards in this deck.
Unlock Deck
k this deck
17
Overloaded methods sharing the same identifier must have the same return type.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
18
What are methods with identical names that have identical parameter lists but different return types?
A) applicable methods
B) illegal methods
C) overloaded methods
D) related methods
A) applicable methods
B) illegal methods
C) overloaded methods
D) related methods
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
19
What type of parameter requires that 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 39 flashcards in this deck.
Unlock Deck
k this deck
20
What type of parameter requires you to indicate the parameter's type and name, and the method receives a copy of the value passed to it?
A) reference parameter
B) output parameter
C) input parameter
D) value parameter
A) reference parameter
B) output parameter
C) input parameter
D) value parameter
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
21
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 39 flashcards in this deck.
Unlock Deck
k this deck
22
What programming principle is violated when using named arguments and why is this important?
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
23
What type of parameter can be given a default value?
A) value parameter
B) reference parameter
C) output parameter
D) array parameter
A) value parameter
B) reference parameter
C) output parameter
D) array parameter
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
24
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 39 flashcards in this deck.
Unlock Deck
k this deck
25
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 39 flashcards in this deck.
Unlock Deck
k this deck
26
When adding optional parameters in a parameter list, what is a valid requirement?
A) The parameters must all be placed locally.
B) The parameters must appear to the right of all mandatory parameters.
C) The parameters must have constant values.
D) The parameters must be defined globally.
A) The parameters must all be placed locally.
B) The parameters must appear to the right of all mandatory parameters.
C) The parameters must have constant values.
D) The parameters must be defined globally.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
27
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 39 flashcards in this deck.
Unlock Deck
k this deck
28
What Visual Studio IDE feature can be used to discover information about methods you are using?
A) CodeIntuit
B) IntelliSense
C) MagicMethod
D) BitDissect
A) CodeIntuit
B) IntelliSense
C) MagicMethod
D) BitDissect
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
29
Under what circumstances can you return a reference from a method?
A) Only when the method performing the return is a static type method.
B) Only when the reference is for an array defined within the method's scope.
C) Only when a method is returning optional parameters with known values as the reference.
D) Only when it is safe to return, such as returning a reference from a method if the reference was passed into the method.
A) Only when the method performing the return is a static type method.
B) Only when the reference is for an array defined within the method's scope.
C) Only when a method is returning optional parameters with known values as the reference.
D) Only when it is safe to return, such as returning a reference from a method if the reference was passed into the method.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
30
What statement regarding overloading methods is accurate?
A) When you create overloaded methods, you write multiple methods with different names but the same parameter list.
B) When you overload a method, the number of parameters must be the same, but the types can be different.
C) An overloaded method must have parameters.
D) The compiler is able to discern which overloaded method version to use based on the arguments you supply for a method call.
A) When you create overloaded methods, you write multiple methods with different names but the same parameter list.
B) When you overload a method, the number of parameters must be the same, but the types can be different.
C) An overloaded method must have parameters.
D) The compiler is able to discern which overloaded method version to use based on the arguments you supply for a method call.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
31
Describe the similarities and differences among method versions when the method is overloaded.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
32
What statement regarding reference parameters is accurate?
A) When you declare a reference parameter in a method header, the argument used to call the method does not require a value.
B) Reference parameters occupy their own memory locations.
C) Reference parameters act as aliases, or pseudonyms, for the same memory location occupied by the values passed to them.
D) The params keyword is used to indicate a reference parameter.
A) When you declare a reference parameter in a method header, the argument used to call the method does not require a value.
B) Reference parameters occupy their own memory locations.
C) Reference parameters act as aliases, or pseudonyms, for the same memory location occupied by the values passed to them.
D) The params keyword is used to indicate a reference parameter.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
33
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 39 flashcards in this deck.
Unlock Deck
k this deck
34
What is another name for unnamed method arguments?
A) self-documenting arguments
B) optional arguments
C) default arguments
D) positional arguments
A) self-documenting arguments
B) optional arguments
C) default arguments
D) positional arguments
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
35
What is the difference between a reference parameter and an output parameter?
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
36
If a default value is assigned to any variable in a method's parameter list, what must all parameters to the right of that parameter have?
A) An explicit cast.
B) An implicit cast.
C) A local keyword.
D) A default value.
A) An explicit cast.
B) An implicit cast.
C) A local keyword.
D) A default value.
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
37
When naming an argument in a method call using its parameter name, what must come 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 39 flashcards in this deck.
Unlock Deck
k this deck
38
What are the four types of mandatory parameters supported by C#?
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck
39
What type of arguments are ignored for betterness purposes on argument conversions?
A) default arguments
B) explicit arguments
C) local arguments
D) optional arguments
A) default arguments
B) explicit arguments
C) local arguments
D) optional arguments
Unlock Deck
Unlock for access to all 39 flashcards in this deck.
Unlock Deck
k this deck