Friday, May 6, 2011

chapter 5

When writing the documentation comments for a method, you can provide a description of each parameter by using a
==@param tag

Which of the following would be a valid method call for the following method?

public static void showProduct(double num1, int num2)
{
double product;
product = num1 * num2;
System.out.println("The product is " +
product);
}
== showProduct(3.3, 55);

Which of the following would be a valid method call for the following method?

public static void showProduct (int num1, double num2)
{
int product;
product = num1 * (int)num2;
System.out.println("The product is " + product);
}
==showProduct(10, 4.5);

What will be the result of the following code?

int num;
string str = "555";
num = Integer.parseInt(string str) + 5;
==The last line of code will cause an error

What is wrong with the following method call?

displayValue (double x);
==The data type of the argument x should not be included in the method call

You must have a return statement in a value-returning method.
==true

Breaking a program down into small manageable methods
==all of the above

The header of a value-returning method must specify this.
==The data type of the return value

This part of a method is a collection of statements that are performed when the method is executed.
=Method body

In the following code, System.out.println(num), is an example of ________.

double num = 5.4;
System.out.println(num);
num = 0.0;
==A void method


No statement outside the method in which a parameter variable is declared can access the parameter by its name.
==true

Which of the following is not a part of the method header?
==semicolon

A parameter variable's scope is the method in which the parameter is declared.
==true

When an object, such as a String, is passed as an argument, it is
==Actually a reference to the object that is passed

Which of the following is not a benefit derived from using methods in programming?
==. All of the above are benefits

Any method that calls a method with a throws clause in its header must either handle the potential exception or have the same throws clause.
==true

All @param tags in a method's documentation comment must
==Appear after the general description of the method

Given the following method header, which of the method calls would be an error?

public void displayValues(double x, int y)
==displayValue(a,b); // where a is a short and b is a long


To document the return value of a method, use this in a documentation comment.
==The @return tag

A value-returning method can return a reference to a non-primitive type.
==true

When an argument value is passed to a method, the receiving parameter variable is
==Declared in the method header inside the parentheses

Constants, variables, and the values of expressions may be passed as arguments to a method.
==true

This type of method performs a task and then terminates.
==void

Which of the following is not a benefit derived from using methods in programming?
==All of the above are benefits

No statement outside the method in which a parameter variable is declared can access the parameter by its name.
==true

The expression in a return statement can be any expression that has a value.
==true

No comments:

Post a Comment