Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Exposure Java Chapter 7 Multiple Choice Test-A Creating Class Methods This Test Is a KEY DO NOT WRITE ON THIS TEST This test includes program segments, which are not complete programs. Answer such questions with the assumption that the program segment is part of a correct program. Objective 1 - Revisiting the Math Class 01. The Math.sin, Math.cos and Math.tan methods return __________ values. ### (A) (B) (C) (D) 02. The Math.exp(p) method returns the _______________ of argument p. ### (A) (B) (C) (D) trigonometric exponential logarithmic radian log antilog radian value degrees 03. The Math.toDegrees(p) method returns the _______________ of the ______________ value of p. ### (A) (B) (C) (D) 04. Which of the following Math class methods requires more than one parameter? ### (A) (B) (C) (D) log antilog radian degrees exponential radian degrees radian PI ceiling pow toRadians Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 1 5-31-11 05. What is the output of the following program segment? System.out.println(Math.floor(25.01)); System.out.println(Math.floor(25.49)); System.out.println(Math.floor(25.51)); System.out.println(Math.floor(25.99)); (A) 06. 25 25 26 26 ###(B) 25 25 25 25 (C) 26 26 26 26 (D) Error message What is the output of the following program segment? System.out.println(Math.ceil(25.01)); System.out.println(Math.ceil(25.49)); System.out.println(Math.ceil(25.51)); System.out.println(Math.ceil(25.99)); (A) 07. 25 25 26 26 (B) 25 25 25 25 ###(C) 26 26 26 26 (D) Error message What is the output of the following program segment? System.out.println(Math.round(25.01)); System.out.println(Math.round(25.49)); System.out.println(Math.round(25.51)); System.out.println(Math.round(25.99)); 25 25 26 26 (B) 25 25 25 25 (C) 26 26 26 26 ### (A) (D) Error message 08. What is the output of the following program segment? System.out.println(floor(25.01)); System.out.println(ceil(25.01)); (A) 25 26 (B) 25 25 (C) 26 26 Exposure Java 2011, APCS Edition ###(D) Error message Chapter 07 Test-A Page 2 5-31-11 Objective 2 - User-Declared Class Methods 09. A class method call ### (A) (B) (C) (D) 10. Which of the following Java keywords are used frequently in the declaration of a class method? ### (A) (B) (C) (D) 11. Consider the Java program below. requires that the class identifier precedes the method identifier. may be called with the method identifier only in certain circumstances. is only possible after a new object is constructed. uses the class identifier only for readability. void public static All of the above public class Q11 { public static void main(String args[ ]) { boohiss(); // line 1 boohiss.Q11(); // line 2 Q11.boohiss(); // line 3 } public static void boohiss() { System.out.println("Calling boohiss"); } } Which of the statements in the main method is a proper method call? ### (A) (B) (C) (D) Line 1 only Line 2 only Line 3 only Lines 1 and 3 Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 3 5-31-11 12. Consider the Java program below. public class Q12A { public static void main(String args[ ]) { boohiss(); // line 1 Q12A.boohiss.(); // line 2 Q12B.boohiss(); // line 3 } } class Q12B { public static void boohiss() { System.out.println("Calling boohiss"); } } Which of the statements in the main method is a proper method call? ### (A) (B) (C) (D) Line 1 only Line 3 only Lines 1 and 2 Lines 1 and 3 Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 4 5-31-11 13. What is the output of the following program? public class Q13 { public static void main(String args [ ]) { method1(); method2(); method3(); } public static void method1() { System.out.println("Calling method 1"); } public static void method2() { System.out.println("Calling method 2"); } public static void method3() { System.out.println("Calling method 3"); } } ### (A) Calling method 1 Calling method 2 Calling method 3 (B) Calling method 3 Calling method 2 Calling method 1 (C) method 1 method 2 method 3 (D) Error message Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 5 5-31-11 14. What is the output of the following program? public class Q14 { public static void main(String args [ ]) { method1(); method3(); method2(); } public static void method1() { System.out.println("Calling method 1"); } public static void method2() { System.out.println("Calling method 3"); } public static void method3() { System.out.println("Calling method 2"); } } ### (A) Calling method 1 Calling method 2 Calling method 3 (B) Calling method 1 Calling method 3 Calling method 2 (C) method 1 method 3 method 2 (D) Error message Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 6 5-31-11 15. What is the output of the following program? public class Q15 { public static void main(String args [ ]) { method1(); method2(); method3(); } } class Tango { public static void method1() { System.out.println("Calling method 1"); } public static void method2() { System.out.println("Calling method 2"); } public static void method3() { System.out.println("Calling method 3"); } } ### (A) Calling method 1 Calling method 2 Calling method 3 (B) Calling method 3 Calling method 2 Calling method 1 (C) method 1 method 2 method 3 (D) Error message Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 7 5-31-11 16. What is the output of the following program? public class Q16 { public static void main(String args [ ]) { Tango.method3(); Tango.method2(); Tango.method1(); } } class Tango { public static void method1() { System.out.println("Calling method 1"); } public static void method2() { System.out.println("Calling method 2"); } public static void method3() { System.out.println("Calling method 3"); } } ### (A) Calling method 1 Calling method 2 Calling method 3 (B) Calling method 3 Calling method 2 Calling method 1 (C) method 1 method 2 method 3 (D) Error message Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 8 5-31-11 Objective 3 - User-Declared Parameter Methods 17. ### 18. ### Which of the following statements is true about the use of parameters with Java methods? (A) (B) (C) (D) Methods without parameters can compile, but will not execute correctly. All method declarations require parameters. Many methods use parameters. The use of parameters is optional to increase program readability. What is true about a method declaration with multiple parameters? (A) (B) (C) (D) All parameters must be the same data type. All parameters must be different data types. Parameter types may be the same or they may be different. The parameter declarations depend on the method call. 19. Which of the following method headings uses proper parameter declarations? ### (A) (B) (C) (D) 20. Which of the following method calls might use parameters correctly? ### (A) (B) (C) (D) 21. The parameters in the method call and the method heading must be the same public static void guess(double rate, double hours, int deductions); public static void guess(double rate, hours, int deductions); public static void guess(rate, hours, deductions); public static void guess(7.85, 42.5, 3); guess(double rate, double hours, int deductions); guess(double rate, hours, int deductions); guess(int rate, hours, deductions); guess(7.85, 42.5, 3); I. quantity. II. sequence. III. type. ### (A) (B) (C) (D) (E) I only II only I & II only II & III only I, II & III Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 9 5-31-11 22. What is the output of the following program? public class Q22 { public static void main(String args [ ]) { method1(1); method3(2); method2(3); } public static void method1(int n) { System.out.println("Calling method " + n); } public static void method2(int n) { System.out.println("Calling method " + n); } public static void method3(int n) { System.out.println("Calling method " + n); } } ### (A) Calling method 1 Calling method 2 Calling method 3 (B) Calling method 1 Calling method 3 Calling method 2 (C) method 1 method 3 method 2 (D) Error message Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 10 5-31-11 23. What is the output of the following program? public class Q23 { public static void main(String args [ ]) { Q23.method1(int n = 1); Q23.method2(int n = 2); Q23.method3(int n = 3); } public static void method1(int n) { System.out.println("Calling method " + n); } public static void method2(int n) { System.out.println("Calling method " + n); } public static void method3(int n) { System.out.println("Calling method " + n); } } ### (A) Calling method1 Calling method2 Calling method3 (B) Calling method1 Calling method3 Calling method2 (C) method1 method2 method3 (D) Error message Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 11 5-31-11 24. What is the output of the following program? public class Q24 { public static void main(String args [ ]) { int n = 4; method1(n); method2(n + 2, 3); method3(n + n); } public static void method1(int x) { System.out.println("x = " + x); } public static void method2(int x, int y) { System.out.println("x + y = " + (x + y) ); } public static void method3(int n) { int x = 4; System.out.println("x = " + x); } } ### (A) 4 63 8 (B) x = 4 x + y = 9 x = 4 (C) x = 4 x + y = 63 x = 8 (D) Error message Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 12 5-31-11 Objective 4 - Void Methods and Return Method 25. ### What distinguishes the declaration of a void method? (A) (B) (C) (D) The public keyword in the method heading The static keyword in the method heading The void keyword in the method heading The main keyword in the method heading 26. What distinguishes the declaration of a return method? ### (A) (B) (C) (D) 27. What distinguishes a call to a void method? ### (A) (B) (C) (D) 28. What distinguishes a call to a return method? ### (A) (B) (C) (D) The return keyword in the method body The static keyword in the method heading The data type declaration in the method heading (do not confuse with parameter data types) Both A and C The method call is the only part of a complete program statement. The method call provides a value, which is used in the program statement. The method call includes the void keyword. The method call includes the return keyword. The method call is the only part of a complete program statement. The method call provides a value, which is used in the program statement. The method call includes the void keyword. The method call includes the return keyword. Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 13 5-31-11 29. What is the output of the following program? public class Q29 { public static void main(String args [ ]) { int x = 25; int y = 10; Calc.add(x,y); Calc.sub(x,y); Calc.mul(x,y); Calc.div(x,y); } } class Calc { public static void add(int p, int q) { int result = p + q; System.out.println(p + " + " + q + " = " + result); } public static void sub(int p, int q) { int result = p - q; System.out.println(p + " - " + q + " = " + result); } public static void mul(int p, int q) { int result = p * q; System.out.println(p + " * " + q + " = " + result); } public static void div(int p, int q) { int result = p / q; System.out.println(p + " / " + q + " = " + result); } } (A) 25 25 25 25 + * / 10 10 10 10 (D) Error message ###(B) 25 25 25 25 + * / 10 10 10 10 Exposure Java 2011, APCS Edition = = = = 35 15 250 2 Chapter 07 Test-A (C) 35 15 250 2 Page 14 5-31-11 30. What is the output of the following program? public class Q30 { public static void main(String args [ ]) { int x = 25; int y = 10; System.out.println(Calc.add(x,y)); System.out.println(Calc.sub(x,y)); System.out.println(Calc.mul(x,y)); System.out.println(Calc.div(x,y)); } } class Calc { public static void add(int p, int q) { int result = p + q; System.out.println(p + " + " + q + " = " + result); } public static void sub(int p, int q) { int result = p - q; System.out.println(p + " - " + q + " = " + result); } public static void mul(int p, int q) { int result = p * q; System.out.println(p + " * " + q + " = " + result); } public static void div(int p, int q) { int result = p / q; System.out.println(p + " / " + q + " = " + result); } } ### (A) 25 25 25 25 + * / 10 10 10 10 (D) Error message (B) 25 25 25 25 + * / 10 10 10 10 Exposure Java 2011, APCS Edition = = = = 35 15 250 2 Chapter 07 Test-A (C) 35 15 250 2 Page 15 5-31-11 31. What is the output of the following program? public class Q31 { public static void main(String args [ ]) { int x = 25; int y = 10; System.out.println(x + " + " + y + " = " + Calc.add(x,y)); System.out.println(x + " - " + y + " = " + Calc.sub(x,y)); System.out.println(x + " * " + y + " = " + Calc.mul(x,y)); System.out.println(x + " / " + y + " = " + Calc.div(x,y)); } } class Calc { public static int add(int p, int q) { int result = p + q; return result; } public static int sub(int p, int q) { int result = p - q; return result; } public static int mul(int p, int q) { return p * q; } public static int div(int p, int q) { return p / q; } } (A) 25 25 25 25 + * / 10 10 10 10 (D) Error message ###(B) 25 25 25 25 + * / 10 10 10 10 Exposure Java 2011, APCS Edition = = = = 35 15 250 2 Chapter 07 Test-A (C) 35 15 250 2 Page 16 5-31-11 32. What is the output of the following program? public class Q32 { public static void main(String args [ ]) { int x = 25; int y = 10; Calc.add(x,y); Calc.sub(x,y); Calc.mul(x,y); Calc.div(x,y); } } class Calc { public static int add(int p, int q) { int result = p + q; return result; } public static int sub(int p, int q) { int result = p - q; return result; } public static int mul(int p, int q) { return p * q; } public static int div(int p, int q) { return p / q; } } ### (A) 25 25 25 25 + * / 10 10 10 10 (D) No output (B) 25 25 25 25 + * / 10 10 10 10 Exposure Java 2011, APCS Edition = = = = 35 15 250 2 Chapter 07 Test-A (C) 35 15 250 2 Page 17 5-31-11 33. What is the output of the following program? public class Q33 { public static void main(String args [ ]) { int x = 25; int y = 10; Calc.add(x,y); Calc.sub(x,y); Calc.mul(x,y); Calc.div(x,y); } } class Calc { public static void add(int p, int q) { int result = p - q; System.out.println(p + " - " + q + " = " + result); } public static void sub(int p, int q) { int result = p + q; System.out.println(p + " + " + q + " = " + result); } public static void mul(int p, int q) { int result = p / q; System.out.println(p + " / " + q + " = " + result); } public static void div(int p, int q) { int result = p * q; System.out.println(p + " * " + q + " = " + result); } } (A) 25 25 25 25 + * / 10 10 10 10 = = = = (E) Error message 35 15 250 2 (B) 25 25 25 25 + * / 10 10 10 10 Exposure Java 2011, APCS Edition = = = = 15 35 2 250 ###(C) 25 25 25 25 Chapter 07 Test-A + / * Page 18 10 10 10 10 = = = = 15 35 2 250 5-31-11 (D) 1 2 3 4 34. What is the output of the following program? public class Q34 { public static void main(String args [ ]) { int x = 25; int y = 10; System.out.println(x + " + " + y + " = " + Calc.add(x,y)); System.out.println(x + " - " + y + " = " + Calc.sub(x,y)); System.out.println(x + " * " + y + " = " + Calc.mul(x,y)); System.out.println(x + " / " + y + " = " + Calc.div(x,y)); } } class Calc { public static int add(int p, int q) { int result = p + q; return result; } public static int sub(int p, int q) { int result = p + q; return result; } public static int mul(int p, int q) { return p / q; } public static int div(int p, int q) { return p * q; } } (A) 25 25 25 25 + * / 10 10 10 10 = = = = (E) Error message 35 15 250 2 ###(B) 25 25 25 25 + * / 10 10 10 10 Exposure Java 2011, APCS Edition = = = = 15 35 2 250 (C) 25 25 25 25 Chapter 07 Test-A + / * Page 19 10 10 10 10 = = = = 15 35 2 250 5-31-11 (D) 1 2 3 4 35. What is the output of the following program? public class Q35 { public static void main(String args [ ]) { int x = 25; int y = 10; System.out.println(Calc.add(x,y)); System.out.println(Calc.sub(x,y)); System.out.println(Calc.mul(x,y)); System.out.println(Calc.div(x,y)); } } class Calc { public static String add(int p, int q) { int sum = p + q; String result = (String) p + " + " + q + " = " + sum; return result; } public static String sub(int p, int q) { int diff = p - q; String result = (String) p + " - " + q + " = " + diff; return result; } public static String mul(int p, int q) { int prod = p * q; String result = (String) p + " * " + q + " = " + prod; return result; } public static String div(int p, int q) { int quot = p + q; String result = (String) p + " / " + q + " = " + quot; return result; } } ### (A) (E) 25 25 25 25 + * / 10 10 10 10 = = = = 35 15 250 2 (B) 25 25 25 25 + * / 10 10 10 10 = = = = 15 35 2 250 (C) 25 25 25 25 + / * 10 10 10 10 = = = = 15 35 2 250 Error message Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 20 5-31-11 (D) 1 2 3 4 36. What is the output of the following program? public class Q36 { public static void main(String args [ ]) { int x = 25; int y = 10; System.out.println(Calc.add(x,y)); System.out.println(Calc.sub(x,y)); System.out.println(Calc.mul(x,y)); System.out.println(Calc.div(x,y)); } } class Calc { public static String add(int p, int q) { int sum = p + q; String result = (String) p + " + " + q + " = " + sum; return “1”; } public static String sub(int p, int q) { int diff = p - q; String result = (String) p + " - " + q + " = " + diff; return “2”; } public static String mul(int p, int q) { int prod = p * q; String result = (String) p + " * " + q + " = " + prod; return “3”; } public static String div(int p, int q) { int quot = p + q; String result = (String) p + " / " + q + " = " + quot; return “4”; } } (A) 25 25 25 25 + * / 10 10 10 10 = = = = (E) Error message 35 15 250 2 (B) 25 25 25 25 + * / 10 10 10 10 Exposure Java 2011, APCS Edition = = = = 15 35 2 250 (C) 25 25 25 25 Chapter 07 Test-A + / * Page 21 10 10 10 10 = = = = 15 35 2 250 5-31-11 ###(D) 1 2 3 4 Objective 5 - Making a Utility Library Class 37. ### The program file, Lab05a.java, uses two classes, which are Lab05a and Util. Which of the following statements is true about the use of these classes? (A) (B) (C) (D) Each class must be placed in a separate file. Both classes must be placed in the same file. It is possible to place both classes in separates files or in the same file. It is only possible to place the two classes in separate files if you create a package. 38. What types of methods should be placed in a user-declared Utility class? ### (A) (B) (C) (D) 39. What type of methods are used by a Utility class? ### (A) (B) (C) (D) Math class methods only All types of practical methods found in the Math class, DecimalFormat and others like it. Only those methods that are necessary to the program using the Utility class. Methods that are often used in many programs, like Center, Skip, Justify, etc. Void methods only Return methods only Void methods and return methods with or without parameters Void methods and returns methods with parameters only 40. Why would you create and use a Utility class? ### (A) (B) (C) (D) You can re-use methods, which you created for previous programs. It makes programs less cluttered when frequently needed tasks are kept in a separate file. You can customize such a class for the style programs that you write. All of the above Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 22 5-31-11 Objective 6 - Fundamental Program Design 41. The Java compiler checks for ### (A) (B) (C) (D) (E) 42. Which of the following are fundamental program design considerations? ### (A) (B) (C) (D) (E) 43. Which of the following variable names is not a self-commenting identifier? ### (A) (B) (C) (D) (E) 44. Multiple methods that perform similar actions should be ### (A) (B) (C) (D) (E) correct program syntax. correct program logic. consistent program statement indentations. the use of meaningful variable identifiers. the proper implementation of methods. Programs should use self-commenting identifiers. Control structures need to use a consistent indentation style. Specific tasks should be placed in modules, called methods. The main method should be used for program sequence, not large numbers of program statements. All of the above netPay deductions k checkingBalance grossPay placed in their own class. placed inside the main method. placed in the same class as the main method. all be placed in a Utility class. changed to a single method. Exposure Java 2011, APCS Edition Chapter 07 Test-A Page 23 5-31-11