程式碼:
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,不知各位的高見如何?還煩請解惑,謝謝!
keyword: is a, has a, 在java有這個觀念…不妨搜尋看看吧…
謝謝您喔!
Really appreciated work…thanks ..I hope your site wil get gud traffic