1、重载和覆盖1. Methods and varibles that do the background work of a class are known as implementation details. The implementation details encapsulated class should be given which access? c A. Public B. The default C. Private /*/ D. Protected E. It does not matter 2. Which of the following is not a benefit
2、 of encapsulation? A. Clarity of code B. Code efficiency C. The ability to add funtionality later on D. Modification requires less coding changes 3. Given: 1. public class Rectangle 2. 3. 4. public class Square extends Rectangle 5. What is the relationship between Rectangle and Square? b /*/ A. has
3、a B. is a C. Its both an is a and has a relationship. D. The relationship is neither an is a or a has a relationship. 4. Given: 1. public class Vehicle 2. private Engine theEngine; 3. 4. 5. public class Engine 6. What is the relationship between Vehicle and Engine? a /*/ A. has a B. is a C. Its both
4、 an is a and has a relationship. D. The relationship is neither an is a or a has a relationship. 5. Given: 1. public interface Moveable 2. public void moveObject(); 3. 4. 5. public class Bitmap implements Moveable 6. public void moveObject() 7. /body omitted 8. 9. What is the relationship between Mo
5、vable and Bitmap? b A. has a B. is a C. Its both an is a and has a relationship. D. The relationship is neither an is a nor a has a relationship. 6. Given: 1. class SuperTest 2. public double getNumber() 3. return Math.random() * 100; 4. 5. 6. 7. class Test extends SuperTest 8. public int getNumber(
6、) 9. return (int) (Math.random() * 100); 10. 11. public static void main(String args) 12. Test t = new Test(); 13. System.out.println(t.getNumber(); 14. 15. Which of these results could occur from this code? (Choose all that apply) f /*/ A. 59 B. 34.234 C. 134.234 D. 134 E. 100 F. This code will not
7、 compile. 7. Given: 1. class SuperTest 2. public double getNumber() 3. return Math.random() * 100; 4. 5. 6. 7. class Test extends SuperTest 8. public int getNumber(int max) 9. return (int) (Math.random() * max); 10. 11. 12. public Integer getNumber(int max) 13. int temp = (int) (Math.random() * max)
8、; 14. return new Integer(temp); 15. 16. 17. public static void main(String args) 18. Test t = new Test(); 19. System.out.println(t.getNumber(); 20. 21. Which of these statements is true? b A. The code will not compile correctly because line 19 is trying to call a method that does not exist for the c
9、lass Test. B. The code does not compile because of line 12 C. The code does not compile because of line 14 D. There is no ambiguity as to the reutrn type in line 12; therefore, this code will compile and output a double value greater than or equal to 0 and less than 100. E. This code will not compil
10、e because the getNumber() methods in the Test class must all have return types of double. 8. Given: 1. public class A 2. public static void main(String args) 3. new A().printResult(1, abc, 4); 4. 5. private void printResult(int a, long b, int c) 6. System.out.println(a + b + c); 7. 8. private void p
11、rintResult(long a, String b, int c) 9. System.out.println(a + b + c); 10. 11. Which of these statements is true? b A. The code will not compile correctly because a long and a String may not be added together in line 9. B. The code will compile and run and will display 1abc4 in the standard output. B
12、. The code will compile and run and will display 11234 in the standard output. D. The code will compile and will throw a NumberFormatException.9. When a subclass method has the same name, parameter list, and return type as a method in the parent class, this method is said to be what? d A. Extended B
13、. Overloaded C. Overextended D. Overridden /*/ 10. Which of the following must match exactly for overloaded methods to compile correclty? (Choose that all apply) d A. The parameter list B. The return type C. The exception thrown D. None of the above 11. Given: 1. public class Test 2. public static v
14、oid main(String args) 3. new Test().foo(1, 2); 4. 5. private void foo(int a, int b) 6. System.out.println(int); 7. 8. private void foo(long a, int b) 9. System.out.println(long); 10. 11. What will happen when you compile and run this program? a A. The code will compile and run, and display int. B. T
15、he code will compile and run, and display long. C. The code will not compile. D. The code will compile, but throw a runtime exception when executed. 12. Given: 1. public class Parent 2. public void execute() throws Exception 3. / body omitted 4. 5. 6. public class Child extends Parent 7. private voi
16、d execute() throws ClassCastException 8. / body omitted 9. 10. What will happen when you compile this program? a A. The program will compile successfully. B. The program will not compile because the execute() in the subclass throws a different exception than in the parent class. C. The program will
17、not compile because the execute() in the subclass has less accessibility than in the parent class. D. The program will not compile because the execute() in the subclass has less accessibliity and throws a different exception than in the parent class. 13. Given: 1. public class A 2. public void baz()
18、 3. System.out.println(A); 4. 5. 6. public class B extends A 7. public static void main(String args) 8. A a = new B(); 9. a.baz(); 10. 11. public vod baz() 12. System.out.println(B); 13. 14. What will happen when you compile and run this program? b A. The program compiles, runs, and display A in the
19、 standard output. B. The program compiles, runs, and display B in the standard output. C. The program compiles, but throws a runtime exception. D. The program does not compile. 14. Given: 1. public class A 2. public static void main(String args) 3. new A().baz(1, 2); 4. 5. private void baz(int a, in
20、t b) 6. System.out.println(baz); 7. 8. private void foo(int a, int b) 9. System.out.println(first); 10. 11. private boolean foo(int a, int b) 12. System.out.println(second); 13. return true; 14. 15. Which of the following statements is true? A. The program compiles, runs, and displays first in the s
21、tandard output. B. The program compiles, runs, and displays second in the standard output. C. The program compiles, runs, and displays baz in the standard output. D. The program does not compile. 15. Given: 1. public class Test 2. protected void start() throws ClassCastException 3. / body omitted 4.
22、 5. 6. 7. public class Child extends Test 8. public void start() throws Exception 9. / body omitted 10. 11. What will happen when you compile this program? A. The program will compile successfully. B. The program will not compile because the start() in the subclass throws a different exception than
23、in the parent class. C. The program will not compile because the start() in the subclass is public, whereas it is protected in the parent class. D. The program will not compile because the start() in the subclass has different accessibility and throws a different exception than in the parent class.1
24、6. When two or more methods in the same class have the same name, they are said to be what? A. An implementation detail B. Overridden C. An interface D. Overloaded 17. Given: 1. public class Example 2. public static void main(String args) 3. new Example().locate(1.0, 2); 4. 5. private void locate(do
25、uble a, long b) 6. System.out.println(double-long); 7. 8. private void locate(long a, int b) 9. System.out.println(long-int); 10. 11. What will happen when you compile and run this program? b A. The code will compile, run and display double-long. B. The code will compile, run and display long-int. C
26、. The code will not compile. D. The code will compile, but throw a runtime exception when executed. 18. Given: 1. class SuperTest 2. public SuperTest() 3. System.out.println( Super! ); 4. 5. 6. 7. class Test extends SuperTest 8. public static void main(String args) 9. new Test(); 10. 11. public Test
27、() 12. super(); 13. this( Great! ); 14. 15. 16. public Test(String name) 17. System.out.println(name); 18. 19. What is the result of this code? f/*thissuper*/ A. Great! Super! B. Super! Great! C. Super! Super! Great! D. Great! E. Super! F. This code will not compile. 19. Given: 1. public class Test
28、2. public static void main(String args) 3. new Test(4); 4. 5. public Test() 6. System.out.println(okay); 7. 8. public Test(int i) 9. 10. 11. Which of the following lines of code should be inserted at line 11 so that the output of the program is okay? c A. super(); B. this; C. Test(); D. this(); E. super(); 20. Given: 1. public class
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1