Chapter 6 - Arrays, Chapter 7, Chapter 8
A method declaration might contain _____. a. declared accessibility b. a nonstatic modifier c. multiple return types d. parameters separated by dots
a
A method's type is also its _____. a. return type b. accessibility c. parameter type d. scope
a
Assume you declare a variable as int x = 100; and correctly pass it to a method with the declaration private static void IncreaseValue(int x). There is a single statement within the IncreaseValue() method: x = x + 25;. Back in the Main() method, after the method call, what is the value of x? a. 100 b. 125 c. It is impossible to tell. d. The program will not run.
a
Assume you have declared a method as follows: private static double CalculateDiscount(int acct = 0, double price = 0, double discount = 0) Which of the following is a legal method call? a. CalculateDiscount(); b. CalculateDiscount(200.00); c. CalculateDiscount(3000.00. 0.02); d. None of the above are legal.
a
Suppose the value of isRateOK() is true, and the value of isQuantityOK() is false. When you evaluate the expression isRateOK() || isQuantityOK(), which of the following is true? a. Only the method isRateOK() executes. b. Only the method isQuantityOK() executes. c. Both methods execute. d. Neither method executes.
a
When an array is passed to a method, the method has access to the array's memory address. This means an array is passed by _____. a. reference b. value c. alias d. orientation
a
Which of the following is a good reason for creating methods within a program? a. Methods are easily reusable. b. Because all methods must be stored in the same class, they are easy to find. c. The Main() method becomes more detailed. d. All of these are true.
a
What is a correct declaration for a method that receives two double arguments. calculates and displays the difference between them, and returns nothing? a. private static void CalcDifference(double price1, price2) b. private static void CalcDifference(double price1, double price2) c. Both of these are correct. d. None of these are correct.
b
Assume you declare a variable as int x = 100; and correctly pass it to a method with the declaration private static void IncreaseValue(ref int x). There is a single statement within the IncreaseValue() method: x = x + 25;. Back in the Main() method, after the method call, what is the value of x? a. 100 b. 125 c. It is impossible to tell. d. The program will not run.
b
Correctly overloaded methods must have the same ____. a. return type b. identifier c. parameter list d. All of the above.
b
If you want to create a method that other methods in other classes can access without limitations, you declare the method to be _____. a. unlimited b. public c. shared d. unrestricted
b
In C#, a method must include all of the following except a _________. a. return type b. access modifier c. body d. closing curly brace
b
In the method call PrintTheData(double salary);, salary is the __________ parameter. a. formal b. actual c. proposed d. preferred
b
Suppose you have declared a method named private static void CalculatePay(double rate). When a method calls the CalculatePay() method, the calling method _____. a. must contain a declared double named rate b. might contain a declared double named rate c. cannot contain a declared double named rate d. cannot contain any declared double variables
b
Suppose you have declared a variable as int myAge = 21;. Which of the following is a legal call to a method with the declaration private static void AMethod(int num)? a. AMethod(int 55); b. AMethod(myAge); c. AMethod(int myAge); d. AMethod();
b
When one of a method's parameters is optional, it means that _____. a. no arguments are required in a call to the method b. a default value will be assigned to the parameter if no argument is sent for it c. a default value will override any argument value sent to it d. you are not required to use the parameter within the method body
b
When you declare a value parameter, you precede its name with _____. a. nothing b. a data type c. the keyword val and a data type d. the keyword ref and its data type
b
Which of the following is an illegal method declaration? a. private static void CreateStatement(int acctNum, double balance = 0.0) b. private static void CreateStatement(int acctNum = 0, double balance) c. private static void CreateStatement(int acctNum = 0, double balance = 0) d. All of these are legal.
b
Which of the following pairs of method declarations represent correctly overloaded methods? a. private static void Method(int a) private static void Method(int b) b. private static void Method(double d) private static int Method() c. private static double Method(int e) private static int Method(int f) d. Two of these are correctly overloaded methods.
b
When you declare an array as int[] temperature = {0, 32, 50, 90, 212, 451};, the value of temperature.Length is _____________________.
b. 6 (how many elements are in it
Which of the following traits do the BinarySearch() and Sort() methods have in common?
b. Both methods belong to the System.Array class.
The BinarySearch() method is inadequate when ________________.
b. The array holds duplicate values and you want to find them all.
In an array, every element has the same __________.
b. data type
Assume an array is defined as int[] nums = {2, 3, 4, 5};. Which of the following would display the values in the array in reverse?
b. for (int x = 3; x >= 0; --x) Write(nums[x]);
Initializing an array is _______________ in C#.
b. optional
. A parameter array _____. a. is declared using the keyword params b. can accept any number of arguments of the same data type c. Both of these are true. d. None of these are true.
c
A mandatory parameter ____. a. is any argument sent to a method b. is preceded by the keyword man c. requires an argument to be sent from a method call d. All of the above are true.
c
A program contains the method call PrintTheData(salary);. In the method definition, the name of the formal parameter must be __________. a. salary b. any legal identifier other than salary c. any legal identifier d. omitted
c
Assume you have declared a method as follows: private static double ComputeBill(int acct, double price, double discount = 0) Which of the following is a legal method call? a. ComputeBill(); b. ComputeBill(1001); c. ComputeBill(1001, 200.00); d. None of the above are legal.
c
Methods are ambiguous when they __________. a. are overloaded b. are written in a confusing manner c. are indistinguishable to the compiler d. have the same parameter type as their return type
c
Suppose the value of isRateOK() is true, and the value of isQuantityOK() is false. When you evaluate the expression isRateOK() && isQuantityOK(), which of the following is true? a. Only the method isRateOK() executes. b. Only the method isQuantityOK() executes. c. Both methods execute. d. Neither method executes.
c
What is a correct declaration for a method that receives two double arguments and sums them, but does not return anything? a. private static void CalcSum(double firstValue, double secondValue) b. private static void CalcSum(double price1, double price2) c. Both of these are correct. d. None of these are correct.
c
When you use a method, you do not need to know how it operates internally. This feature is called _____. a. scope management b. selective ignorance c. implementation hiding d. privacy
c
Which is not a type of method parameter in C#? a. value b. reference c. forensic d. output
c
Which of the following is a difference between a reference parameter and an output parameter? a. A reference parameter receives a memory address; an output parameter does not. b. A reference parameter occupies a unique memory address; an output parameter does not. c. A reference parameter must have an initial value; an output parameter need not. d. A reference parameter need not have an initial value; an output parameter must.
c
When an ages array is correctly initialize using {20, 30, 40, 50}, as in Question 8, then the value of ages[1] is _____________.
c. 30 (life begins at 0)
If you define an array to contain 10 elements, then the highest array subscript you can use is _________________.
c. 9
Assume an array is defined as int[] nums = {7, 15, 23, 5};. Which of the following would place the values in the array in descending numeric order?
c. Array.Sort(nums); Array.Reverse(nums); (sort THEN reverse)
Which of the following doubles every value in a 10-element integer array named amount?
c. both of these for(int x = 9; x >=0; --x) *=2; and foreach(int number in amount) *=2;
The operator used to create objects is _________.
c. new
. The process of determining which overloaded version of a method to execute is overload _____ a. confusion b. infusion c. revolution d. resolution
d
A method is declared as private static double CalcPay(int hoursWorked). Suppose you write a Main() method in the same class that contains the declarations int hours = 35; and double pay;. Which of the following represents a correct way to call the CalcPay() method from the Main() method? a. hours = CalcPay(); b. hours = Main.CalcPay(); c. pay = CalcPay(hoursWorked); d. pay = CalcPay(hours);
d
Assume you have declared a method as follows: private static double DisplayData(string name = "XX", double amount = 10.0) Which of the following is an illegal method call? a. DisplayData(name : "Albert"); b. DisplayData(amount : 200, name : "Albert"); c. DisplayData(amount : 900.00); d. All of these are legal.
d
Assume you have declared a method with the following header: private static void DisplayScores(params int[] scores) Which of the following method calls is valid? a. DisplayScores(20); b. DisplayScores(20, 33); c. DisplayScores(20, 30, 90); d. All of the above are valid.
d
At most, a class can contain _________ method(s). a. 0 b. 1 c. 2 d. any number of
d
Every method declaration must contain _________. a. a statement of purpose b. declared accessibility c. the static modifier d. a return type
d
If you use the keyword modifier static in a method header, you indicate that the method _________. a. cannot be copied b. can be called only once c. cannot require parameters d. is called without an object reference
d
Suppose you have declared an integer array named scores, and you make the following method call: TotalScores(scores, num : 1); Of the following overloaded method definitions, which would execute? a. private static void TotalScores(int[] scores) b. private static void TotalScores(int[] scores, int num) c. private static void TotalScores(int[] scores, int num = 10, int code = 10) d. The program would not compile.
d
When you write the method declaration for a method that can receive a parameter, you need to include all of the following items except _________. a. a pair of parentheses b. the type of the parameter c. a local name for the parameter d. an initial value for the parameter
d
Which of the following pairs of method declarations represent correctly overloaded methods? a. private static void MethodA(int a) private static void MethodA(int b, double c) b. private static void MethodB(double d) private static void MethodB() c. private static double MethodC(int e) private static double MethodD(int f) d. Two of these are correctly overloaded methods.
d
Which type of method parameter receives the address of the variable passed in? a. a value parameter b. a reference parameter c. an output parameter d. two of the above
d
If you use the BinarySearch() method, and the object you seek is not found in the array, ______________.
d. A negative value is returned.
Which of the following correctly declares an array of six integers?
d. Int[] array = new int[6];
The value placed within square brackets after an array name is ______________.
d. all of the above (a subscript, an index and always an integer)
Which of the following correctly declares an array of four integers?
d. all of these (all contain 4 integers)
Which of the following declares an integer array that contains eight rows and five columns?
d. int [ , ] num = new int [8, 5]
Which of the following adds 10 to every value in a 16-element integer array named points?
d. neither of these (a goes above known universe (> not <) and b says points not sub)
Two arrays that store related information in corresponding element positions are _____________.
d. parallel arrays
When an ages array is correctly initialize using {20, 30, 40, 50}, as in Question 8, then the value of ages[4] is _____________.
d. undefined (since life begins at 0, 3 is the highest option)
When you declare an array of six double elements but provide no initialization values, the value of the first element is ________________.
d. unknown (nothing is declared in new array)