请使用继承关系实现下列描述:(较难)自行车和豪车属于车类型车(car):车牌号(ci
请使用继承关系实现下列描述:
(较难)
自行车和豪车属于车类型
车(
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();
}