Deck 7: Methods: a Deeper Look
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
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/95
Play
Full screen (f)
Deck 7: Methods: a Deeper Look
1
Methods are called by writing the name of the method followed by enclosed in parentheses.
A) a condition
B) arguments
C) a counter
D) None of the above.
A) a condition
B) arguments
C) a counter
D) None of the above.
B
2
A method is invoked by a.
A) return statement
B) method header
C) method call
D) None of the above.
A) return statement
B) method header
C) method call
D) None of the above.
C
3
Which of the following correctly calls the Math class method Sqrt with a value of 36
A) Sqrt(36);
B) Math.Sqrt(36);
C) Math.Sqrt = 36;
D) None of the above.
A) Sqrt(36);
B) Math.Sqrt(36);
C) Math.Sqrt = 36;
D) None of the above.
B
4
When may an app omit the string[] args parameter from the Main header
A) when the app does not need to use strings
B) when the app does not take command-line arguments
D) All of the above
A) when the app does not need to use strings
B) when the app does not take command-line arguments
D) All of the above
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
5
Programmers write to define specific tasks that may be used at many points in a program.
A) classes
B) methods
C) modules
D) None of the above.
A) classes
B) methods
C) modules
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
6
Methods should be large and perform as many tasks as possible.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
7
A static variable represents class-wide information.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
8
Information may be methods.
A) passed to
B) returned from
C) manipulated in
D) All of the above.
A) passed to
B) returned from
C) manipulated in
D) All of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
9
Prepackaged methods and classes are available for use in theNET Framework Class Library.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
10
Repeating high-quality,high-performance code in a program helps ensure higher qual
ity programs.
ity programs.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
11
The return type of a method's return value is specified in the method call.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
12
Methods can return at most one value.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
13
Methods defined by the programmer may consist only of predefinedNET method calls.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following describes a static variable
A) a variable with one copy shared by all class objects
B) a variable whose value may not be changed
C) all of the above
D) None of the above.
A) a variable with one copy shared by all class objects
B) a variable whose value may not be changed
C) all of the above
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
15
A return type of is specified for a method that does not return a value.
A) nothing
B) null
C) void
D) None of the above.
A) nothing
B) null
C) void
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
16
Methods that call themselves are known as ________ methods.
A) reiterative
B) self-calling
C) repeat-calling
D) recursive
A) reiterative
B) self-calling
C) repeat-calling
D) recursive
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following can be arguments to methods
A) constants
B) variables
C) expressions
D) All of the above
A) constants
B) variables
C) expressions
D) All of the above
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
18
The technique of dividing large programs into simple problems is known as divide and conquer.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
19
Any variable declared with keyword const is a constant and cannot be changed after it's declared and initialized.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
20
_________ methods can be called without the need for an object of the class to exist.
A)special
B)independent
C)static
D)dependent
A)special
B)independent
C)static
D)dependent
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
21
A program contains a copy of a static variable for each object that's instantiated.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
22
Let x be a double.How can you typecast a double into a float
A) implicitly
B) x(float)
C) (float)x
D) x = float
A) implicitly
B) x(float)
C) (float)x
D) x = float
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
23
Which statement is false
A) If a method does not return a value, the return-value-type in the method declaration can be omitted.
B) Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error.
C) Re-declaring a method parameter as a local variable in the method's body is a compilation error.
D) Forgetting to return a value from a method that should return a value is a compilation error.
A) If a method does not return a value, the return-value-type in the method declaration can be omitted.
B) Placing a semicolon after the right parenthesis enclosing the parameter list of a method declaration is a syntax error.
C) Re-declaring a method parameter as a local variable in the method's body is a compilation error.
D) Forgetting to return a value from a method that should return a value is a compilation error.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
24
The Math class provides only methods.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
25
Which keyword can you use to immediately give control back to a method's caller
A) continue
B) break
C) return
D) next
A) continue
B) break
C) return
D) next
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
26
To call a static method,use the _________ name followed by a period,and the method with its arguments.
A) class's
D) All of the above
A) class's
D) All of the above
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
27
The parameter list in the method header and the arguments in the method call must agree in:
A) number
B) type
C) order
D) all of the above
A) number
B) type
C) order
D) all of the above
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
28
A(n)conversion occurs when a type is converted to a type that can hold more data.
A) implicit
B) widening
C) explicit
D) None of the above.
A) implicit
B) widening
C) explicit
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
29
To access the class's non-static members,a static method must use a reference to an object of the class.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
30
When a return statement executes,control proceeds immediately to the first statement after the method that issues the return.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
31
How are various parameters separated in the method header
A)brackets
B)braces
C)commas
D)periods
A)brackets
B)braces
C)commas
D)periods
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
32
An int must be explicitly cast to which of the following
A) float
B) double
C) sbyte
D) None of the above.
A) float
B) double
C) sbyte
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
33
When an object is concatenated with a string:
A) a compilation error occurs
B) a runtime error occurs
C) the object's ToString method is implicitly called
D) the object's class name is used
A) a compilation error occurs
B) a runtime error occurs
C) the object's ToString method is implicitly called
D) the object's class name is used
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
34
Converting a simple type to another simple type may change the value.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
35
Method arguments may not be expressions.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
36
strings can be concatenated only with the method Concat.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
37
Conversions that cause data loss are not allowed in C#.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
38
Main is declared static so the execution environment can invoke Main without creating an instance of the class.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
39
Methods are called by writing the name of the method followed by a left brace followed by the argument (or a comma-separated list of arguments)of the method followed by a right brace.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
40
A static method can ________.
A) call only other static methods of the same class directly
B) manipulate only static fields in the same class directly
C) be called using the class name and a dot (.)
D) All of the above
A) call only other static methods of the same class directly
B) manipulate only static fields in the same class directly
C) be called using the class name and a dot (.)
D) All of the above
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
41
It's always better to write your own code than to search and use a class from the FCL.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
42
To compare a simple-type value to the underlying value of an enumeration constant,you must use a cast operator to make the two types match.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
43
A is provided to a random number generator to ensure the same sequence of numbers is not generated during each execution.
A) date
B) parameter
C) seed
D) None of the above.
A) date
B) parameter
C) seed
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
44
Which of these statements best defines scope
A) Scope refers to the classes that have access to a variable.
B) Scope determines whether a variable's value can be altered.
C) Scoping allows the programmer to use a class without using its fully qualified name.
D) Scope is the portion of a program that can refer to an entity by its simple name.
A) Scope refers to the classes that have access to a variable.
B) Scope determines whether a variable's value can be altered.
C) Scoping allows the programmer to use a class without using its fully qualified name.
D) Scope is the portion of a program that can refer to an entity by its simple name.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
45
Which directive allows you to use the Framework Class Library
A)import
B)using
C)load
D) namespace
A)import
B)using
C)load
D) namespace
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
46
Any variables declared in a for statement header have block scope within that statement.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
47
Random-number generator scaling is the process of:
A) causing each number in a range to have equal likelihood of being generated
B) modifying the range from which a number will be generated
C) calculating a sequence of numbers to be generated
D) None of the above.
A) causing each number in a range to have equal likelihood of being generated
B) modifying the range from which a number will be generated
C) calculating a sequence of numbers to be generated
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
48
The values produced by Random are weighted so that some values will be generated with greater frequency than others.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
49
Values returned by the Random class method Next are pseudo-random numbers.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
50
What does the Framework Class Library hold
A)namespaces
B) classes
A)namespaces
B) classes
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
51
Which of the following cannot be an enum's underlying type
A)sbyte
B)int
C)ulong
D)double
A)sbyte
B)int
C)ulong
D)double
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
52
If a local variable in a method has the same name as a field of the method's class,what will occur
A)an error is generated
B) the field is "hidden" until the method is finished executing
C) the field will override the variable from the method
D) None of the above.
A)an error is generated
B) the field is "hidden" until the method is finished executing
C) the field will override the variable from the method
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
53
Which of the following statements describes block scope
A) It begins at the opening { of the class declaration and terminates at the closing }
B) It limits label scope to only the method in which it is declared.
C) It begins at the identifier's declaration and ends at the terminating right brace (}).
D) It is valid for one statement only.
A) It begins at the opening { of the class declaration and terminates at the closing }
B) It limits label scope to only the method in which it is declared.
C) It begins at the identifier's declaration and ends at the terminating right brace (}).
D) It is valid for one statement only.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
54
By including using System;at the top of a source program,you can use the unqualified class name,Console,instead of the fully qualified class name,System.Console.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
55
If a change is made to an underlying value in an enumeration,you must change the pro
gram in every place that the old value was used.
gram in every place that the old value was used.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
56
A(n)is a value type that contains a set of constant values.
A) enumeration
B) object
C) set
D) None of the above.
A) enumeration
B) object
C) set
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
57
The Next method produces a random number from zero up to and including the number provided by the programmer in the method call.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
58
Identifiers declared within a class have
A) block scope
B) class scope
C) local scope
D) None of the above.
A) block scope
B) class scope
C) local scope
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
59
A particular seed value passed to the Random class's constructor causes the Random object to always produce the same series of random numbers.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
60
Values produced by random-number generating methods are truly random.There is no way to predict the next result.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
61
Overloaded methods always have the same _________.
A) method name
B) return type
C) number of the parameters
D) order of the parameters
A) method name
B) return type
C) number of the parameters
D) order of the parameters
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
62
Any parameter in a parameter list can be declared as an optional parameter.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
63
The order of a method's parameters is insignificant.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
64
Consider the following Cube method:
Static int Cube(int x)
{
Return x * x * x;
}
Which of the following statements is false
A) 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.
B) 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.
C) 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.
D) 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";
Static int Cube(int x)
{
Return x * x * x;
}
Which of the following statements is false
A) 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.
B) 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.
C) 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.
D) 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";
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
65
The local variables used in each invocation of a method during an app's execution are stored in the ________.
A)program execution stack
B)activation record
C)stack frame
D)All of the above.
A)program execution stack
B)activation record
C)stack frame
D)All of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
66
Which of the following is not part of recursion
A) recursive call
B) recursion step(s)
C) base case(s)
D) None of the above.
A) recursive call
B) recursion step(s)
C) base case(s)
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
67
When calling a method,you must specify the arguments in the same order that the corresponding parameters are declared in the method's parameter list.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
68
Since memory in a computer is finite,a stack error may occur known as stack overflow.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
69
Methods of a class can access all members defined in that class.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
70
C# 6 introduces a new concise syntax for ________:
A) methods that contain only a return statement that returns a value
B) read-only properties in which the get accessor contains only a return statement
C) methods that contain single statement bodies.
D) All of the above
A) methods that contain only a return statement that returns a value
B) read-only properties in which the get accessor contains only a return statement
C) methods that contain single statement bodies.
D) All of the above
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
71
Methods of the same name can be declared in the same class,as long as they have different sets of parameters (determined by the number,types and order of the parameters).
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
72
A recursion step normally includes the keyword return.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
73
Overloaded methods normally perform similar tasks,but on different types of data.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
74
Which of the following will violate the rules of overloading methods
A)Methods with the same signatures but different return types.
B)Methods with different signatures but the same return type.
C)Methods with different number of arguments.
D)Method with different types of arguments.
A)Methods with the same signatures but different return types.
B)Methods with different signatures but the same return type.
C)Methods with different number of arguments.
D)Method with different types of arguments.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
75
Stacks are _____________ data structures.
A) FIFO
B) Random
C) LIFO
D) None of the above.
A) FIFO
B) Random
C) LIFO
D) None of the above.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
76
Optional parameters enable you to specify default argument values for specific parameters.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
77
An overloaded method is one that
A) has a different name than another method, but the same parameters.
B) has the same name as another method, but different parameters.
C) has the same name and parameters as a method defined in another class.
D) has the same name and parameters, but a different return type than another method.
A) has a different name than another method, but the same parameters.
B) has the same name as another method, but different parameters.
C) has the same name and parameters as a method defined in another class.
D) has the same name and parameters, but a different return type than another method.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
78
A local variable or reference declared in a block can be used in blocks in which that block is nested.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
79
A recursive method is a method that:
A) calls another method
B) calls itself
C) has no return type
D) None of the above
A) calls another method
B) calls itself
C) has no return type
D) None of the above
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck
80
A recursive method knows directly how to solve only the base case.
Unlock Deck
Unlock for access to all 95 flashcards in this deck.
Unlock Deck
k this deck