Modified Exampl
Modified Exampl
fi
edexampl
e
publ
i
ccl
assCar{
/
/At
tri
but
esoft
heCarcl
ass
pr
ivat
eSt
ri
ngmodel
;
pr
ivat
einty
ear
;
/
/Const
ruct
or
publ
i
cCar
(St
ri
ngmodel
,i
nty
ear
){
t
his.
model
=model
;
t
his.
year=y
ear
;
/
/Met
hodt
odi
spl
aycari
nfor
mat
ion
publ
i
cvoi
ddi
spl
ayI
nfo(
){
Sy
stem.
out
.pr
int
ln(
"Manuf
act
ureYear
:"+y
ear
);
Sy
stem.
out
.pr
int
ln(
"Model
:"+model
);
/
/Set
terf
ormodel
publ
i
cvoi
dset
Model
(St
ri
ngnewModel
){
model
=newModel
;
/
/Set
terf
ory
ear
publ
i
cvoi
dset
Year
(i
ntnewYear
){
y
ear=newYear
;
/
/Usageexampl
e:
publ
i
ccl
assMai
n{
publ
i
cst
ati
cvoi
dmai
n(St
ri
ng[
]ar
gs){
Carmy
Car=newCar
("Toy
ota"
,2020)
;//Cr
eat
eanobj
ectofCarcl
ass
my
Car
.di
spl
ayI
nfo(
);/
/Cal
lthei
nst
ancemet
hod
my
Car
.set
Model
("
Honda"
);/
/Changecar
'smodel
my
Car
.set
Year
(2022)
;//Changecar
'smanuf
act
urey
ear
my
Car
.di
spl
ayI
nfo(
);/
/Cal
lthei
nst
ancemet
hodagai
ntodi
spl
ayupdat
edi
nfo