請使用繼承關(guān)系實現(xiàn)下列描述:(較難)自行車和豪車屬于車類型車(car):車牌號(ci
請使用繼承關(guān)系實現(xiàn)下列描述:
(較難)
自行車和豪車屬于車類型
車(
car
):車牌號(
cid
)、車型(
dtype
)、價值(
cvalue
)
自行車(
bicycle
):車牌號(
cid
)、車型(
dtype
)、價值(
cvalue
)、鏈條
(
chain
)
豪車(
limo
):車牌號(
cid
)、車型(
dtype
)、價值(
cvalue
)、導航
(guide)
class
car{
protected
String
cid
;
protected
String
dtype
;
protected
int
cvalue
;
public
car(String
id
,String
type
,
int
value
){
cid
=
id
;
dtype
=
type
;
cvalue
=
value
;
}
}
class
bicycle
extends
car{
String
chain
;
public
bicycle(String
id
,String
type
,
int
value
,String
chain
){
super
(
id
,
type
,
value
);
this
.
chain
=
chain
;
}
public
void
display(){
System.
out
.println(
"
自行車車牌號:
"
+
cid
+
"
車型:
"
+
dtype
+
"
價值:
"
+
cvalue
+
"
鏈
條
:"
+
chain
);
}
}
class
limo
extends
car{
public
limo(String
id
,String
type
,
int
value
){
super
(
id
,
type
,
value
);
}
public
void
guide(){System.
out
.println(
"
我有導航功能。
"
);}
public
void
display(){
System.
out
.println(
"
豪車車牌號:
"
+
cid
+
"
車型:
"
+
dtype
+
"
價值:
"
+
cvalue
);
guide();
}
}
public
class
testCar {
public
static
void
main(String[]
args
) {
//
TODO
Auto-generated method stub
bicycle
bike
=
new
bicycle(
"28"
,
"
永久
"
,300,
"KMC"
);
bike
.display();
limo
li
=
new
limo(
"A0000"
,
"
幻影
"
,2000000);
li
.display();
}