Classes Objects
Aclassdefinesthepropertiesandbehaviorsofanobject
structure h blueprintforcreatingmultipleinstances objectsthat
of
shareproperties behaviors
Anybjectorments is an entitythatcontainsdata methodsthatoperate
onthatdata
created
specific
data
[Link] unique
froma instance behavior are created dynamicallyduringprogramexecutionandcan interacttogether
ad class
ClassStructure publicclass myclass
Variables
Variables Constructors
usedtodescribeobjects Methods
ex carobject studentobject 3
model
year age Ypa hame
ex
2 Constructors publicclassCar
samenameas class stringmake
lookslikea method string model Variables
withoutareturn type int year
usedwhenever [Link] initializedcreated
public [Link]
Methods make ma
y
usedtoread
variables constructor
orchangethem Jett
publicstaticvoidmain string args
Car cl newCau BMW series 2020
Car ch newCaulTesla models 2022
Systemoutprintn 1 make
[Link] 2model
Note
ifyoutry toprintanobject exsystemoutprinted
yougetits
reference locationin
memory notvalueof
its variables
Howcanweprintobject'sinfo
Printeachvariableusingdotoperator
it
createstaticmethodthatreceivesobjectas parameterthenprints usindotoperator
Publicclass Car
Huariables constructors
publicstaticvoiddisplay
Info Carc
SystemoutprintIn Make cmake cmodel year
Model
c
year
publicstaticvoidmain string args
Car cl newCaul BMW 3series 2020
Car c newCaulTesla models 2022
displayInfo d
Info c2
display
1youcanalso use this
Info newCarlVw
display ID4 2023
instancemethodsdon'thavethestatickeyword
haveacesstoclassvariablewithoutneedingto objecttothem
pass an
Infol
publicvoiddisplay
systemoutprintn Make make
Instance model model
year year
Info Carc
publicstaticvoiddisplay
static systemoutprintn Make tomake
model cmodel cyear
year
howtocallinstance methods ms ddisplayIntoll
cdisplayIntoll
referto classvariables byaddingthisbefore them
you can
publicCarlstringmake Stringmodel intyear
thismake make
this
knowsthatthismake is theclass argument whilemake
java
withoutthis is theparameter intheargumentslistoftheconstructor