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

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

  Q4.You are writing a set of classes related to cooking and have created your own exception hierarchy derived from java.lang.Exception as follows Exception
  +-- BadTasteException
  +-- BitterException
  +-- SourException
  Your base class, “BaseCook” has a method declared as follows int rateFlavor(Ingredient[] list) throws BadTasteException A class, “TexMexCook”, derived from BaseCook has a method which overrides BaseCook.rateFlavor(). Which of the following are legal declarations of the overriding method?
  a. int rateFlavor(Ingredient[] list) throws BadTasteException
  b. int rateFlavor(Ingredient[] list) throws Exception
  c. int rateFlavor(Ingredient[] list) throws BitterException
  d. int rateFlavor(Ingredient[] list)
  Q5.You are working on an aquarium simulation class named Aquarius. You already have a method which adds a Fish object to the aquarium and returns the remaining fish capacity. This method has the following declaration.
  public int addFish( Fish f )
  Now you want to provide for adding a whole shoal of fish at once. The proposed method declaration is protected boolean addFish( Fish[] f ) The idea being that it will return true if there is more room in the tank or false if the tank now too full. Which of the following statements about this proposal are true?
  a. This technique is called overloading.
  b. This technique is called overriding.
  c. The compiler will reject the new method because the return type is different.

  d. The compiler will reject the new method because the access modifier is different.

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

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

</p>  Q6.You have created a TimeOut class as an extension of Thread, the purpose being to print a “Time's Up” message if the Thread is not interrupted within 10 seconds of being started.
  Here is the run method which you have coded.
  1. public void run(){
  2. System.out.println(“Start!”);
  3. try {
  4. Thread.sleep(10000 );
  5. System.out.println(“Time's Up!”);
  6. } catch(InterruptedException e) {
  7. System.out.println(“Interrupted!”);
  8. }
  9. }
  Given that a program creates and starts a TimeOut object, which of the following statements is true?
  a. Exactly 10 seconds after the start method is called, “Time's Up!” will be printed.
  b. Exactly 10 seconds after “Start!” is printed, “Time's Up!” will be printed.
  c. The delay between “Start!” being printed and “Time's Up!” will be 10 seconds plus or minus one tick of the system clock.
  d. If “Time's Up!” is printed you can be sure at least 10 seconds have elapsed since “Start!” was printed.
  4. acd
  5. a
  6. d
页: [1]
查看完整版本: 2011年JAVA认证模拟题第二阶段(2)