会计考友 发表于 2012-8-4 12:33:16

2011年JAVA认证模拟题第二阶段(3)

  Q7.What is the output of the following program?
  1. class Base {
  2. int x=3;
  3. public Base() {}
  4. public void show() {
  5. System.out.print(“ The value is “ + x);
  6. }
  7. }
  8. class Derived extends Base {
  9. int x=2;
  10. public Derived() {}
  11. public void show() {
  12. System.out.print(“ The value is “ + x);
  13. }
  14. }
  15. public class Test {
  16. public static void main(String args[]) {
  17. Base b = new Derived();
  18. b.show();
  19. System.out.println(“The value is “ +b.x);
  20. }

  21. } // end of class Test
  a. The value is 3 The value is 2
  b. The value is 2 The value is 3
  c. The value is 3 The value is 3
  d.The value is 2 The value is 2
  Q8.What is the output of the following code?
  1. public class Note {
  2. public static void main(String args[]) {
  3. String name[] = {”Killer”,”Miller”};
  4. String name0 = “Killer”;
  5. String name1 = “Miller”;
  6. swap(name0,name1);
  7. System.out.println(name0 + “,” + name1);
  8. swap(name);
  9. System.out.println(name + “,” + name);
  10. }
  11. public static void swap(String name[]) {
  12. String temp;
  13. temp=name;
  14. name=name;

  15. name=temp;

会计考友 发表于 2012-8-4 12:33:17

2011年JAVA认证模拟题第二阶段(3)

</p>  16. }
  17. public static void swap(String name0,String name1) {
  18. String temp;
  19. temp=name0;
  20. name0=name1;
  21. name1=temp;
  22. }
  23. } // end of Class Note
  a. Killer,Miller followed by Killer,Miller
  b. Miller,Killer followed by Killer,Miller
  c. Killer,Miller followed by Miller,Killer
  d. Miller,Killer followed by Miller,Killer
  Q9.What is the output of the following program?
  1. public class Q11 {
  2. static String str1 = “main method with String[] args”;
  3. s tatic String str2 = “main method with int[] args”;
  5. public static void main(String[] args) {
  6. System.out.println(str1);
  7. }
  10. public static void main(int[] args) {
  11. System.out.println(str2);
  12. }
  13. }
  a. Duplicate method main(), compilation error at line 5.
  b. Duplicate method main(), compilation error at line 10.
  c. Prints “main method with String[] args”.
  d. Prints “main method with int[] args”.
  7. b
  8. c
  9. c
页: [1]
查看完整版本: 2011年JAVA认证模拟题第二阶段(3)