SCJP一個關於繼承及介面的問題

點閱人數:78次 十一月 9th, 2009 by ㄚ琪 | 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

程式碼:

package inheritance_interface;

interface Runner {   public void run();}

class Locomotion {}

class Vehicle {}

class Car extends Vehicle {   String hood;}

class SportsCar extends Car implements Runner {   public void run() {   }}

class Motorcycle implements Runner {   public void run() {   }}

public class Howto {}

which of the following is true of the above?

A.Motorcycle is an Vehicle.

B.Motorcycle is a Run.

C.Car is a Vehicle.

D.Car is a Runner.

E.Motorcyle has a String.

G.Sports car has a Runner.

答案:B、C、F

這是來自徹底征服SCJP 6認證,p.4-104,試題51的問題!

問題的解釋很詭異:

選項A是正確的,Motorcycle雖然實作了Runner介面但是卻沒有繼承Vehicle所以Motorcycle並不是一個Vehicle。=>都說不是Vehicle了,還說A是正確的?答案也沒有A啊,解釋詭異1

選項B就是正確的了,因為Motorcycle實作了Runner介面所以Motorcylce是一個Runner這個說法沒錯。啊怎跟題目的Motorcycle is a Run不一致?這是題意、答案、解釋不一致的詭異2

選項E是錯誤的,Motorcycle有一個Vehicle,可是我們檢視的結果Motorcycle以及其所實作的Runner介面都沒有Vehicle 這個屬性,所以這個選項錯誤。感覺是Motorcycle有一個Vehicle是真兌現什世界說的,後面的說法是根據題意說的!

選項G的Sports car還分一個空格說,真不知該怎麼說這個排版!

所以個人覺得答案只有C跟F,不知各位的高見如何?還煩請解惑,謝謝!

喜歡這篇文章嗎?請幫這篇加入共用書籤,謝謝:
  • Digg
  • del.icio.us
  • Google Bookmarks
  • Hemidemi
  • MyShare
  • Technorati
  • StumbleUpon
  • Diigo
  • Facebook
  • Twitter
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Tags: , , , ,

3 Responses to “SCJP一個關於繼承及介面的問題”

  1. Shengyu 說道:

    keyword: is a, has a, 在java有這個觀念…不妨搜尋看看吧…

  2. Really appreciated work…thanks ..I hope your site wil get gud traffic

發表迴響

名稱:(必)
電子郵件位址(並不會被公開)(必)
個人網站


Fatal error: Call to undefined function cbnet_comment_captcha() in /home/job/public_html/wp-content/themes/achi/comments.php on line 84