29.7k views
20 votes
Consider a method defined with the header:

public static void doStuff(double a, int b)
Which of the following method calls is NOT legal?
int x = 9;
int y = 36;
doStuff (x, y);
doStuff (5.5, 7);
doStuff (5, 7);
doStuff (5, 7.5);
int z = 55;
doStuff (z, z + 1);
Consider the following variables and method representing a student.
private double gpa;
private int gradeLevel;

public boolean honorRoll()
{
/* Missing Code */
}
A student is placed on the honor role if their GPA is 3.5 or above, and they are in the 11th or 12th grade.
Which of the following correctly replaces /* missing code */ so that the method works as intended?
I. if ((gpa >= 3.5) && ((gradeLevel == 11) || (gradeLevel == 12)))
return true;
return false;
II. boolean pass = false;
if (gpa >= 3.5);
pass = true;
if ((gradeLevel == 11) || (gradeLevel == 12))
pass = true;
return pass;
III. if ((gpa >= 3.5) || ((gradeLevel == 11) || (gradeLevel == 12)))
return true;
return false;
I only
II only
III only
II & III
I, II, & III
When a parameter is a(n) ______ data type, any changes made in a method are preserved.
int
binary
actual
class
primitive
What mistake is in the following code?
public static void mystery(double a) {
System.out.println(a * 3.14);
return a * 3.14;
}
It should say return true;
The return value should be a boolean.
The parameter should be a boolean type.
A method whose return type is void cannot return a value.
A method cannot return a double.
What return statement may be used in the following method?
public static int p() {
//...
}
return 1;
return {1, 2, 3};
return int[]{1, 2, 3};
return new int[]{1, 2, 3};
return p[1]
When you pass a double variable to a method, the method receives ______.
a copy of the memory address
the reference of the variable
the length of the variable
a copy of the variable
binary of the memory address
What is output by the following code?
String q = "onomatopoeia";
String r = "splat";
System.out.println( q.indexOf( r.charAt (3)));
4
5
12
a
t

User SolvingJ
by
4.5k points

1 Answer

2 votes

Answer:

Following are the solution to this question:

Step-by-step explanation:

In the first question, the answer is "doStuff (5, 7.5);" because in the method definition the second parameter is an integer type and it is the double type, that's why it is not legal.

In the second question, the answer is "Option I" because in this, it uses a conditional statement that checks the gpa value is greater than equal to 3.5 and also check grade value equal to 11 or 12.

In the third question, the answer is "Class" because it is used to pass the value by reference for the method.

In the fourth question, the answer is "A method whose return type is void cannot return a value".

In the fifth question, the answer is "return 1" because it doesn't accept any value and its return type is an integer.

In the sixth question, the answer is "a copy of the variable".

In the seventh question, the answer is "4". because it uses the index method, in which it finds the character value of r string, that is equal to "a" and finds this value in q string that is available on the 4 index number.

User Brent Taylor
by
4.2k points