Unit 4 Review Assignment 2 What is the most important reason
Unit 4 Review Assignment
2. What is the most important reason for creating methods within a program?
o a. Methods are easily reusable.
o b. Because all methods must be stored in the same class, they are easy to find.
o c. The Main() method becomes more detailed.
o d. All of these are true.
4. A method declaration must contain _________.
o a. a statement of purpose
o a. declared accessibility
o c. the static modifier
o d. a return type
6. When you write the method declaration for a method that can receive a parameter, you need to include all of the following items except _____.
o a. a pair of parentheses
o b. the type of the parameter
o c. a local name for the parameter
o d. an initial value for the parameter
8. Suppose you have declared a method named public static void CalculatePay (double rate). Which is true of a method that calls the CalculatePay() method?
o a. The calling method must contain a declared double named rate.
o b. The calling method might contain a declared double named rate.
o c. The calling method cannot contain a declared double named rate.
o d. The calling method can contain no declared double variables.
10. A program contains the method call PrintTheData (salary);. In the method definition, the name of the formal parameter must be________.
o a. salary
o b. any legal identifier other than salary
o c. any legal identifier
o d. omitted
12. A method is declared as double CalcPay(int hoursWorked). Suppose you write a Main() method containing int hours = 35; and double pay;. Which of the following represents a correct way to call the CalcPay() method from the Main() method?
o a.hours = CalcPay();
o b.hours = CalcPay(pay);
o c.pay = CalcPay(hoursWorked);
o d.pay = CalcPay (hours);
14. Which type of method parameter receives the address of the variable passed in?
o a. a value parameter
o b. a reference parameter
o c. an output parameter
o d. two of the above
16. Assume you declare a variable as int x = 100; and correctly pass it to a method with the declaration public 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?
o a. 100
o b. 125
o c. It is impossible to tell.
o d. The program will not run.
18. Methods are ambiguous when they _________.
o a. are overloaded
o b. are written in a confusing manner
o c. are indistinguishable to the compiler
o d. have the same parameter type as their return type
20. Which of the following pairs of method declarations represent correctly overloaded methods?
o a. public static void method(int a) public static void method(int b)
o b. public static void method(double d) public static int Method()
o c. public static double Method(int e) public static int Method(int f)
o d. Two of these are correctly overloaded methods.
Solution
2. What is the most important reason for creating methods within a program?
o a. Methods are easily reusable.
4. A method declaration must contain _________.
o d. a return type
6. When you write the method declaration for a method that can receive a parameter, you need to include all of the following items except _____.
o d. an initial value of the parameter
8. Suppose you have declared a method named public static void CalculatePay (double rate). Which is true of a method that calls the CalculatePay() method?
o a. The calling method must contain a declared double named rate.
10. A program contains the method call PrintTheData (salary);. In the method definition, the name of the formal parameter must be________.
o c. any legal identifier
12. A method is declared as double CalcPay(int hoursWorked). Suppose you write a Main() method containing int hours = 35; and double pay;. Which of the following represents a correct way to call the CalcPay() method from the Main() method?
o d.pay = CalcPay (hours);
14. Which type of method parameter receives the address of the variable passed in?
o d. two of the above
16. Assume you declare a variable as int x = 100; and correctly pass it to a method with the declaration public 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?
o a. 100
18. Methods are ambiguous when they _________.
o c. are indistinguishable to the compiler
20. Which of the following pairs of method declarations represent correctly overloaded methods?
o d. Two of these are correctly overloaded methods.


