0% found this document useful (0 votes)
6 views

Modified Exampl

Java code

Uploaded by

dopaxat791
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Modified Exampl

Java code

Uploaded by

dopaxat791
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Modi

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

You might also like