
Chp. 8, Methods
Quiz by DEREK HOWARD
Feel free to use or edit a copy
includes Teacher and Student dashboards
Measure skillsfrom any curriculum
Measure skills
from any curriculum
Tag the questions with any skills you have. Your dashboard will track each student's mastery of each skill.
With a free account, teachers can
- edit the questions
- save a copy for later
- start a class game
- automatically assign follow-up activities based on students’ scores
- assign as homework
- share a link with colleagues
- print as a bubble sheet
20 questions
Show answers
- Q1Assuming myMethod( ) returns a string, which of the following statements is valid?All of these are validSystem.out.println(myMethod());myMethod();String result = "Return value is " + myMethod();30s
- Q2Given the following function declaration: private static double mystery(double a, int b){ return a *b; } What is the result of executing the following code? int a = 3; double b = 2.0; System.out.println(mystery(a,b));6.0 will be printed to the consoleNothing, a run-time exception will be thrown6 will be printed to the consoleNothing, there is a compile-time error30s
- Q3. Given the following method definitions: private static void mystery(double a) { System.out.print("double! "); } private static void mystery(int a) { System.out.print("int! "); } What will be the output of the following code? mystery(1); mystery(1.0);int! double!double! int!It is impossible to predictDuplicate function names results in a compiler error30s
- Q4Given the following method: private static void mystery(int a) { a = 3; System.out.print(a + " "); } What is the result printed to the console when the following code is executed? int a = 4; mystery(a); System.out.print(a + " ");4 34 43 43 330s
- Q5What does the following method return if a = -8.0 and b = 2.0? private static double mystery(double a, double b) { if (a > 0) return a * b; else if (a < 0) return a / b; return 0; }a * b0a / bAn exception will be thrown30s
- Q6What is wrong with the following declaration for the empty() method? public class Tester { } public static void empty() { }All methods other than main() must be declared as privateIt is not enclosed within the curly braces of the Tester classAll methods must return some valueThe method does not receive any input parameters30s
- Q7What is wrong with the following function declaration? static void errorProne(int a, double a) return a + a;It has duplicate parameter namesIt is missing curly bracesIt is declared as a void but returns some dataAll of these things are wrong30s
- Q8What keyword must be used on any method (function) on your class that is called from your main() method?privatestaticpublicvoid30s
- Q9Which of the following method names are invalid?_1a()1_a()_a1()a_1()30s
- Q10Which of the following statements best reflects “functional decomposition”?Careful analysis of your code to ensure it is error-freeBreak a large task into a series of smaller, simpler methodsKeep your method bodies as long as possibleGet rid of old methods you haven’t used in a while30s
- Q11What three words are often used interchangeably to represent a function?function, method, subroutinefunction, loop, flow controlfunction, main, declarationfunction, purpose, task30s
- Q12What two symbols define the beginning and ending of the function body?{ and }( and )[ and ]/* and */30s
- Q13Which of the following locations are valid places to add a function definition?These are all valid locationsOutside a class bodyInside a class body, but outside other function bodiesInside other function bodies30s
- Q14Which of the following functions correctly declares a double and a string parameter?static void myFunction(double p1, string p2)static void myFunction(double, string)static void myFunction(p1, p2)static void myFunction(int myDouble, int myString)30s
- Q15What can you do with function parameters within a function body?You can change their data typeYou can read the parameters but not change their local valueYou can write the parameters but not read their valueThe same things you can do with any other locally declared variable30s