程式码:
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