Professional Documents
Culture Documents
Oopj Unit3
Oopj Unit3
Oopj Unit3
constants
Sa list of
Am emumeTation
a clas6 EYpe
e n u m e r a t i o m
define
keyöre).
Am
emum
ustng
Craabed
e n u m e r a t t o n
is
Am MathedS
comstrwctors,
aan
have
e m u m e r a t i o m
Am
and umstamce yavtables
Advamtages
ÜmproVes type safety
Emumeratiom
soELCH.
used in
ean b e easily
E m u m e r a t t o n
traverSed
Can be easily
E m u m e r a t t o n
CTeate an e n u m e a tto).
to
Java proqram
class Edemo
HNER,
SUMMER,
SPRINNG,
Season1
Public enU AUTOMN
s: Season-valuesC))
for (Season
System o u t pr ntlo(s),
valueOfC
)
ads
valuesl ,
intermally EOTE
dava compiler compie
in
m
at
enu
ithin
the
methodS
and rdinal
oro )
Values)
containing
an
aray
retumS
method
The Values)
ValueOfC)
the value ot gEven
TetuTnS
method
he valueof ( )
Constant enum
OTdinall )
enum Value
C l a s s OT
OutStde of the class
qenericS
enerics allowS us to Create a clas6, interface angl
Generic clasS
A clasS that Cam be used oith amy ype of data g
E-9
J a v a program to Create a Generc class.
Private T data
this. data =
data
Public T g e tData )
TetusD thtS°data
class
GCdemo
JAVA),
CLASS RETORNS-"++
ystem-Out print ( nmlt GENERIC
y-get Datal) )
output
RETURNS - J AVA.
GENERIC CLASS
qenertc Method
dacta
be used
o t t h amy tyre of
A method that can
E9
to create a GeneTic Method
Java Proqram
class Demo
genericsMethol ( T dala)
Public 2T> Void
METHOD)
GENERIC
System- aut println (
PASSED: "+ data)
DATA
printn(
System- out
class GMdemo
Integer>genertcs Method ( 5)
d
GENERIC METHOD
PASSED : 25
DATA
AdNantbages of GeneriCS
I code Reusabüity
e cam Osike (de
With the help of gemerics,
genericS code
3.
3 Used oith Collecttons
The collections frame hiork USeS the