CSC 120 Chapter 5

Ace your homework & exams now with Quizwiz!

What will be the result after the following code executes? int num; string str = "555"; num = Integer.parseInt(string str) + 5; a. num will be set to 560 b. str will have a value of "560" c. The last line of code will cause an error. d. Neither num nor str will be changed.

C

When writing documentation comments for a method, you can provide a description of each parameter by using a __________. a. @comment tag b. @doc tag c. @param tag d. @return tag

C

A value-returning method must specify __________ as its return type in the method header. a. an int b. a double c. a boolean d. Any valid data type

D

Given the following method, which of these method calls is valid? public static void showProduct (double num1, int num2) { double product; product = num1 * num2; System.out.println("The product is " + product); } a. showProduct("5", "40"); c. showProduct(10, 4.5); b. showProduct(10.0, 4.6); d. showProduct(3.3, 55);

D

In a general sense, a method is __________. a. a plan b. a statement inside a loop c. a comment d. a collection of statements that perform a specific task

D

Local variables can be initialized with __________. a. constants b. parameter values c. the result of an arithmetic operation d. Any of these.

D

The lifetime of a method's local variable is __________. a. the duration of the program b. the duration of the class to which the method belongs c. the duration of the method that called the local variable's method d. only while the method is executing

D

To create a method, you must write its __________. a. header b. return type c. body d. definition

D

To document the return value of a method you can use a __________. a. @comment tag b. @returnValue tag c. @param tag d. @return tag

D

What will be returned from the following method? public static int methodA( ) { double a = 8.5 + 9.5; return a; } a. 18.0 b. 18 c. 8.0 d. This is an error.

D

Which of the following is not part of a method header? a. return type b. method name c. parentheses d. semicolon

D

A __________ type of method performs a task and then terminates. a. value-returning b. void c. local d. simple

B

A special variable that holds a value being passed into a method is called a(n) __________. a. modifier b. parameter c. alias d. argument

B

All @param tags in a method's documentation must __________. a. end with a */ b. appear after the general description of the method c. appear before the method header d. span several lines

B

Assume that the following method header is for a method in class A. public void displayValue(int value) Assume that the following code segments appear in another method, also in class A. Which contains a legal call to the displayValue method? a. int x = 7; void displayValue(x); b. int x = 7; displayValue(x); c. int x = 7; displayValue(int x); d. int x = 7; displayValue(x)

B

In a @return tag statement the description __________. a. cannot be longer than one line b. describes the return value c. must be longer than one line d. describes the parameter values

B

In the following code, System.out.println(num) is an example of __________. double num = 5.4; System.out.println(num); num = 0.0; a. a value-returning method b. a void method c. a complex method d. a local variable

B

Methods are commonly used to: a. speed up the compilation of a program b. break a program down into small manageable pieces c. emphasize certain parts of the logic d. document the program

B

Values that are sent into a method are called __________. a. variables b. arguments c. literals d. types

B

When a method tests an argument and returns a true or false value, it should return __________. a. a zero for true and a one for false b. a boolean value c. a zero for false and a non-zero for true d. A method should not be used for this.

B

When an argument value is passed to a method, the receiving parameter variable is __________. a. declared within the body of the method b. declared in the method header inside the parentheses c. declared in the call d. used in the declaration of the argument

B

Which of the following is not a part of a method call? a. method name b. return type c. parentheses d. All of these

B

A __________ is a part of a method that contains a collection of statements that are performed when the method is executed. a. method header b. return type c. method body d. method modifier

C

Given the following method header, which of these method calls is incorrect? public void displayValue(double x, int y); a. displayValue(a, b); // where a is a long and b is a byte b. displayValue(a, b); // where a is an int and b is a byte c. displayValue(a, b); // where a is a short and b is a long d. All of these would give an error.

C

Given the following method header, which of these method calls is incorrect? public void displayValue(int x, int y); a. displayValue(a, b); // where a is a short and b is a byte b. displayValue(a, b); // where a is an int and b is a byte c. displayValue(a, b); // where a is a short and b is a long d. All of these would give an error.

C

Given the following method, which of these method calls is valid? public static void showProduct (int num1, double num2) { int product; product = num1 * (int)num2; System.out.println("The product is " + product); } a. showProduct(5.5, 4.0); b. showProduct(10.0, 4); c. showProduct(10, 4.5); d. showProduct(33.0, 55.0);

C

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens? a. Control is returned to method A. b. Control is returned to method B. c. Control is returned to method C. d. The program terminates.

C

The header of a value-returning method must specify __________. a. the method's local variable names b. the name of the variable in the calling method that will receive the returned value c. the data type of the return value d. All of these must be specified.

C

A method a. may have zero or more parameters b. never has parameter variables c. must have at least two parameter variables d. may not have only one parameter variable

A

A parameter variable's scope is __________. a. the method in which the parameter is declared b. the class to which the method belongs c. the main method d. All of these are true.

A

If you attempt to use a local variable before it has been given a value, __________. a. a compiler error will occur b. the local variable will always contain the value 0 c. the results will be unpredictable d. the local variable will be ignored

A

In the following code, Integer.parseInt(str) is an example of __________. int num; string str = "555"; num = Integer.parseInt(str) + 5; a. a value-returning method b. a void method c. a local variable d. a complex method

A

In the header, the method name is always followed by __________. a. parentheses b. a return type c. a data type d. braces

A

The process of breaking a problem down into smaller pieces is sometimes called __________. a. the divide and conquer method c. top-down programming b. the scientific method d. whole-into-part programming

A

Values stored in local variables __________. a. are lost between calls to the method in which they are declared b. retain their values from the last call to the method in which they are declared c. may be referenced by the calling method d. may be referenced by any other method if the method in which they are declared is a public method

A

What will be returned from the following method? public static double methodA( ) { double a = 8.5 + 9.5; return a; } a. 18.0 b. 18 c. 8 d. 19

A

When an argument is passed to a method __________. a. its value is copied into the method's parameter variable b. its value may be changed within the called method c. Both (a) and (b) are correct. d. Neither (a) nor (b) are correct.

A

When an object, such as a String, is passed as an argument it is __________. a. actually a reference to the object that is passed b. passed by value like any other parameter value c. encrypted d. necessary to know exactly how long the string is when writing the program

A

When you pass an argument to a method you should be sure that the argument's type is compatible with __________. a. the parameter variable's data type b. the method's return type c. the version of Java currently used d. IEEE standards

A

Which type of method performs a task and sends a value back to the code that called it? a. value-returning b. void c. complex d. local

A

You should always document a method by writing comments that appear __________. a. just before the method's definition b. just after the method's definition c. at the end of the file d. only if the method is more than five lines long

A


Related study sets

Chapter 5: Individual Life Insurance Contract - Provisions and Options

View Set

Unit 2. Vocab. B. Complete using the correct form of the words in the box. More than one word might fit in each gap but try to use all the words: concentrate, consider, contemplate, deliberate, gather, grasp, ponder, reckon, suppose.

View Set

Legal/Ethical Aspects of Nursing and Documentation

View Set

Preparing a Business Plan ( Importance and Types of Business Plans )

View Set

ESA - Certified Alarm Technician

View Set