Programming Exam 1 ch 7

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

public int mystery(int x, int y) {if (x >= y) return x - y; elsereturn x + y; } Based on the code in the accompanying figure, what would be the output of the following statement? System.out.println(mystery(8,7)); a. 1 b. 7 c. 8 d. 15

1

public static double secret(int first, double second) { double temp; if (second > first) temp = first * second; elsetemp = first - second; return temp; } Based on the code in the accompanying figure, what would be the output of the following statement? System.out.println(secret(5, 7.0)); a. 5.0 b. 7.0 c. 2.0 d. 35.0

35.0

public int mystery(int x, int y) {if (x >= y) return x - y; elsereturn x + y; } Based on the code in the accompanying figure, what would be the output of the following statement? System.out.println(mystery(8, mystery(2, 1)); a. 5 b. 7 c. 11 d. 13

7

All the methods defined in a class must have different names.

False

Just like the nesting of loops, Java allows the nesting of methods.

False

The return statement must be the last line of the method.

False

The signature of a method consists of only its formal parameter list.

False

The word static is a return type in Java.

False

To use a predefined method, you must know the code in the body of the method.

False

Void methods must have at least one parameter.

False

Void methods use the return statement to return the value 0.

False

You can use the class String to pass strings as parameters to a method and change the actual parameter.

False

Which of the following statements about strings is NOT true? a. When you use the assignment operator to assign a string to a String variable, the computer allocates memory space large enough to store the string. b. When a string is assigned to a String variable, the string cannot be changed. c. The class String contains many methods that allow you to change an existing string. d. A String variable is actually a reference variable.

The class String contains many methods that allow you to change an existing string.

Which of the following statements is NOT true? a. Reference variables do not directly contain the data. b. Reference variables contain the address of the memory space where the data is stored. c. The operator new must always be used to allocate space of a specific type, regardless of the type. d. A String variable is actually a reference variable of the type String.

The operator new must always be used to allocate space of a specific type, regardless of the type.

Actual and formal parameters have a one-to-one correspondence.

True

An actual parameter is a variable or expression listed in a method call.

True

If a formal parameter is a variable of a primitive data type, then after copying the value of the actual parameter, there is no connection between the formal and actual parameter.

True

In Java, return is a reserved word.

True

Reference variables as parameters allow you to return more than one value from a method.

True

Strings assigned to StringBuffer variables can be altered.

True

How can a method send a primitive value back to the caller? a. It cannot send primitive values back to the caller b. By using the return statement c. By assigning the value to one of its parameters d. It can call its caller with the value

b. By using the return statement

public static char methodHeading(int n, double num) Which of the following statements about the method heading in the accompanying figure is NOT true? a. The method has two parameters. b. The method cannot be used outside the class c. methodHeading is an identifier giving a name to this specific method. d. It is a value-returning method of type char.

b. The method cannot be used outside the class

public static char methodHeading(int n, double num) Based on the method heading in the accompanying figure, what is the return type of the value returned? a. static b. char c. int d. num

char

public static double secret(int first, double second) { double temp; if (second > first) temp = first * second; elsetemp = first - second; return temp; } What is the return type of the method in the accompanying figure? a. public b. int c. void d. double

double

public static double secret(int first, double second) { double temp; if (second > first) temp = first * second; elsetemp = first - second; return temp; } Which of the following is NOT part of the heading of the method in the accompanying figure? a. public b. static c. secret(int first, double second) d. double temp;

doubletemp;

The program that tests a method is called a ____ program. a. tester b. driver c. stub d. debugging

driver

int larger(int x, int y) Given the method heading in the accompanying figure, which of the following would be an incorrect demonstration of method overloading? a. int larger(int a, int b) b. intlarger(intx,inty,intz) c. double larger(double x, double y) d. char larger(char x, char y, char z)

int larger(int a, int b)

int larger(int x, int y) Given the method heading in the accompanying figure, which of the following does NOT demonstrate method overloading? a. int larger(int x, int y, int z) b. int larger (char x) c. int max (int x, int y) d. double larger (double x, double y)

int max (int x, int y)

Formal parameters of primitive data types provide ____ between actual parameters and formal parameters. a. one way link b. two way link c. three way link d. no link

one way link

Which modifier is used to specify that a method cannot be used outside a class? a. public b. abstract c. static d. private

private

Which of the following is NOT true about return statements? a. A value-returning method returns its value via the return statement. b. return statements can be used in void methods to return values. c. A method can have more than one return statement. d. Whenever a return statement executes in a method, the remaining statements are skipped and the method exits.

return statements can be used in void methods to return values.

public static double secret(int first, double second) { double temp; if (second > first) temp = first * second; elsetemp = first - second; return temp; } What is the name of the method in the accompanying figure? a. first b. second c. secret d. double

secret

public static double secret(int first, double second) { double temp; if (second > first) temp = first * second; elsetemp = first - second; return temp; } Which of the following is a valid call to the method in the accompanying figure? a. secret(5, 4.8); b. secret(int5,double4.8); c. secret(int x, double y); d. publicstaticintsecret(5,4.8);

secret(5, 4.8);

What is an actual parameter? a. The value passed into a method by a method call b. The value returned by a method c. The type of the method d. A variable declared in the method heading

the value passed into a method by a method call


Kaugnay na mga set ng pag-aaral

AP Lang Declaration of Independence

View Set

Principles of Information Assurance Midterm

View Set

ACloud Guru Certified Cloud Practitioner Practice Exam

View Set

Chapter 26 Study Guide Questions

View Set