Oopj Unit3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Enumeratiom mameal

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

public Static votd nain (trirg argst1)

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)

al the values of enum

ValueOfC)
the value ot gEven
TetuTnS
method
he valueof ( )

Constant enum

OTdinall )

retuTns the index of the


metHod
The odinal(

enum Value

be CTeated oith tm the


emumerat+on can
Am

C l a s s OT
OutStde of the class
qenericS
enerics allowS us to Create a clas6, interface angl

chod that can be Used th difterent types of data

enertcs does mot oTk t t h primitive datottypas

Generic clasS
A clasS that Cam be used oith amy ype of data g

KnoW as Generic class.

E-9
J a v a program to Create a Generc class.

Class qenertcs Class<1>

Private T data

Public GenericsClass (T data)

this. data =
data

Public T g e tData )

TetusD thtS°data
class
GCdemo

Public Stattc votd main (String avgst )

GenericsClass< > (5),


GeneTcs Class< Imteqer = Tew

|mmlt GENERIC cLAss RETURNS-"+t


Oystem- out Print (
get Data( ) )

Generics ClasS< String y = mew Generice CiasS4 >

JAVA),

CLASS RETORNS-"++
ystem-Out print ( nmlt GENERIC
y-get Datal) )

output

GENERIC CUASS RETORNS -

RETURNS - J AVA.
GENERIC CLASS
qenertc Method
dacta
be used
o t t h amy tyre of
A method that can

ts knowD as Generte Method.

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

Static Void main (Stving argsti )


Public

Demo = nen Demo


Method (JAVA")
d.<STüng>qenerics

Integer>genertcs Method ( 5)
d

OutputE GENERIC METHOD

DATA PASSED JAVA

GENERIC METHOD

PASSED : 25
DATA
AdNantbages of GeneriCS

I code Reusabüity
e cam Osike (de
With the help of gemerics,

that oül Ook with ditterent types of data.

Compile -time checking


The bpe parametev Of qemerics PTOVEdes

informatton about the type a daLa usecl tn tne

genericS code

3.
3 Used oith Collecttons
The collections frame hiork USeS the

Conceptof genericS jaYa

You might also like