0 ratings0% found this document useful (0 votes) 79 views36 pagesMethods
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
aati, Wb \ one!
we
ated veg ff “ablock which hore cert
enetructfons +0 perform a fas k.
Varicble
Cond?tons &
Looping otaltment.
klhy we ed e
+ For code mew abfily
Tt reduce Compleatiy of -the preqrara.
U
Syntars
Public ee -
Groketed Nome ts wind
net, ptt Signg. vot te ie
Coo Speettion — Acoess mmactifien velivntyp | methodmane
1
Method signature .
inetuclos
Sh
Cethod implementation Cos) cethod bacid.
eq: claire
t et
pulolte etatic votd emi 0)
* ¢.o.pln cetutto");
0: pln cir’):
public ctatic void main CHring CI ange) .
Ry ani). ¢ — method coll
tmein spa ce
7M, > LOXI ¢.o-pln
(“Yelle”),
/
/
[|*
so.plo (Ht);
Hep aren,
GY wor So create 4 matted per walt calling
clow
£
pu!
¢
sone tt teers | kieran" Ds
ublfe << tatfe void Kot)
v @0. pl Cy biviidoy
5 dbs slab word 30)
ay copin have comput toy Bich"):
blic clotic voPd ki)
en 12-04 B00! ".
public glatPe votd tC?
. Sopln (" End")
public Aatic void in
s Oa Tras Ethieg CP amy
la),
lerc)}
bs (>;
yeyoe yy
9
ae
+ There ane a gpa ‘e| methods |
1. Qlatic method .
2.Non~ Statfe amethod -
1, State Cethod ¢ -
—S These crie the emethode yy hich gontaine Stade
keyword Qn Pls method s&natwre
Suntan’.
Access specifies Static vetumlype method name a
t
5
FD tle can cereale m~no. of lat otal eaerdel cle
A Statfe methods can be ule directly rl ustog
“method rame C ) oo ctan name. mesa mame ¢ 5
a
Static pool Areq | P.g.V. m0)
z copln (ed;
Method treaa
4 claw Tel
puble ctat’e wid mm)
S.o.plnl" Kiran"):
publ?c statlfe votd ml)
£0-Plm (’colanke"):
Public static void main (stingl'T a1q4)
4
me)!
Mae):
mil) 90K —
mre) DOK DL€ “ wlAP for below oequlrement
+ creak 4 senerhods
4 Perform emethad feline from arain ™matbocf
Claw Eq
publ® stale vold key"
copia CK!)
ubite Merce vord) 2 0de
4 soph Ci) ae
publfe ctertic vofd k3Cd
e.o.pln Cn’);
f \
public state vord kat)
.
£0. pln ('u'); a i
t a
publfe .ctaitfe ‘voPd a Cohing C7 avs)
f wo: vy) Ye: qe aga
koa; a x ca
| Ka dgois i | i 4
, | Ree eo "
4 Ka 038 ' a.
3 oo
Satie pool -fres
rein specs | Bonn
KgC)>on3a3 )
kel) 90 UY pre Song
Methrd awca
Ok lI
reo. plnCe): oxey
so pm ys Oxcs
x33
Sopla('n’),-
». Non - State lethod $s
JS Thue aye the amelhods whieh doec nol corlarr
startle keeoord fn: Ps method $fqnatur
syntax: -
Accere spectfien aretuynlype methodname ()
t
f
4 tle can crate n-no. >of mom ~etatPe ae Pree
e ole Oe
\
“Fle camrot dixectly Galt Jacceu the non ~clate melhod
Te cau faccen. : i
syntax:
élanname refernaVarableams =
oat
TV.mMethodname C) 5
new claxzsname. 0)
=
Claw Demo
pubic void m0)
¥ '
G.o-pln (He);
3 ;
public stetfe toid main (sting C) Ain)
s
®Bemo a = neo Demo'l);
ayers
% Aatic pool brea
Method! Ayes
Ox)
JeophCe)* Tor Static ano object eredtion Fe required hey
stor mon —eqatte rmutrod. we required creation q
~ Alon- etatfe methods ae not choral in elalic poo
isle “seahrewnant
~“@. war for below require
4 creak a clas
4 create’ a s (alte riothodd
“) cratd a non-stedlfe ~mnthods
4 Creakt a rman mélhod
“= perform method 7 fox all netted,
clos task i ‘
t pub lfc stalfe void ke)
: é .0.pln (RY:
| 5 pubife ctatic votd” tet)
$
so-pln (7; 2b:
publ soad bs) :
A)
9-0-plm (a); rs
4
public void ty ¢)
£
s-o- pln Cu’):
3
pubtic etat?c vord ™main (sting Et. arg)
$
OY
a / dex Bee 0
Rete
task AR = nevo Epo ; ‘
Ay, Ks Oy t ,
tye P39 O)5 ;
tka. tal); .
3 :ae stad pony malhectaves
“aap pote te |
jee mew fost 0)! Aer On oa |
eye kal rysoxuy a tal
Nea age ee cee
Li aos
Wy
> Catling a method imttde’ aindther wathod)
clan task
Ss
v
pub Se. Static void be)
e S-epln (" Hey");
G0. pln (44);
public static void tit)
f s.o-pln (" ok aye):
: “Key:
public talfc void amar ns J aq)
$
7 9
koe; State pool trea
} 4 “|hitoen
Fi Gsomr
Le Ok Cie mainspace
Meth
Hey ao: | oot ee es
Mite , ox
[copes
$0. deen,
OxKIL
<0: PimCok ay” 3
Macys
— =
eelacs dask > Sortie methed can call
t
=
. Wae -for+-belor equrromen bs
4+ Creak a clay
+ Creat ap clatfe methods
>imethod wll cau a” method ; .
At metnod coPl call atdl metnod , ;
al method wf cath 274 method,
> Create a main method # Ca all the methods
Gmother state method
publfe ctatfe wid ki) divecrly.
so.pln C* Kiram’)s
3 ky C5
publte stalfé votd Ke 0
: s-o. pln (" Rahat”): »
publfe static vofd ka O>
, $-0-plm C* Vipul") +
Kacy: .
3
public ctatfce votd bey 0D
: go pln Cutzoy ") 3 #
3003
eg t fs
pubif. statfe vofd main (otring(l args)
Kod 1) of
kien; Kran al
Ka C96 _ Mipy 0
k - Vipul,
op 43 Rahul
4 Rahul
hetiste Vipul
., Rahul
Nitjoy
Vipul
Reuhut
weLy Wlon-steatfe method can atl ne
Arey
A
claw task
$
“yale method
public vord kn)
f -0.p)m (“mon -stalléc kr metre");
4
public void mts
‘ $.0. pln (mon ~ stalfe b2 method");
kicp;
7 «
public tale vod main (Shing OF args) if
‘ é
Toak. Ans pmo, tenho;
tebe:
t T
; ! af
non-state Cp omerhod .coticd
mon- salve (Cr mathod,
Recagqrment- ms . :
(D wae for below requinemert '
Creat cx clo. >,
4 Cra 4 mon - sath aviathacls
+ Method t cai method 3
4 method 4 cath, method & aie
Feat main method. PN wen ky
“+ Creake a obpeclr, cal at th Prrathed ture
a Obj coli -a Tout
public vord kc)
2
sopin(*krran" 2
ka 05
z
public void k2C)
-
s.0-plnC" Rahul"!
5
public uoid tg 6)
‘sep cs Vipul” 4
publ?c vod byt)
c-o-pln C° Vijay),
Kao
punlfc static void araln
f
Tosk 4) = new Task 0) ;
Tou bh t2 = mew Toutes:
4. k0);
ty. k20)5
he Os
ttyl);
405
tr. cas
2-09;
Fo -buc;
(Shing MI aig’)
fe.
Kerem
Vipol
Rohe
Vipol
Vijo4
fhe
ot
ao Pahl
Vipul
20
afmam space
_
Fask 4) =new teak):
took 42 = new fonte)
[fo. plnCkivan %); ]
0x22
8x23
Oxuy
Ree capt wyey) |
tye)
Print Livan
K3C)
Pont Vipul\
\o?’.
We Non slate ai cating Statfe method :-
13
3 Non elatfe anethod cam cam cau etalig method dreerty,
because of one statte pool ayea- tor ome clan.
_y Statfe methods cam be called direcHy Pron anywhere fra
tne clan:
Example $-
claw +tack op:
N
abit clatte void kil) a
. sopin OK: _ a
public vofd k2C)
In (NS
3 ee
publ?c etal void main Cohing TI avg)
t g \ t
toak ty] new taskod;)
tak Lo = new tok(d;
ey). Ko C9
$ t
Static pool Area _ method Aie< Abed
ox Speed :
f Ox22
rain space (eepmewN)
staak 4 = neo dakoe | 4 =
Aask 49 - ee y Ko 0X22
| da= new tartec): hy 30x22 Ko 0X22
tt. ka);‘Dtatfe method caitfng men — & tale rmethod re
> static method connot- cau non - Stetfe method cltrec
ee \ ly
A Mihenevey we or calla @ mon - state rmetnod ine
StaHe method we need to crea am object
Frample.
Clace task |
2
publ slatt we kc)
: ap
Soph Ck); Pe su
task = mao task ey; N,
te kacns
% \
publ vod kec)
é S+0- ply C'N')5 P a
ie , | . il
Public elatie vot main (hing [] age)
eae Wy
, 495 i oe
j Static pool Area ‘
en Wethod #5
Vpo ext
soplnCk)
Ox22 yin
[e-0.phn Cu!
Ky 90x22
8. WAP for below requirement
2 > Creal actos
Creal’ a on-static meted
7 (all non -ctatit method from rain metrod
* Crealé a static method , ctalic method will catl
1-8 ‘method
7 Gal cfatic method from main method.
ae. ew
. fared
class tak Oo ole:
6 wate word Kr
publ KPra
£ copln ("tram") Poof
sip EEO 5 1 Poop -
tak tn yt
bye Os
3 5 Gk main ,
| ypapite vot) Ks 0)
Eo Jn (“Pooja”) 5
4,
; put eu Veta math Cohing FI nq)
cm 2
ea’ 6 j.094)"| : : ‘
VT RE Ois,
fast ta = new) EEO ov
"i : ky. ks 05
\
: a... iid
ay
Sdasfe Pe «method ( diveety)
Non- clatic. me
—
3
— Mon =ttatie Eeretnod (direetty)
Non-lalie method = —+ Matte method C directiy)
Satie method —— > Non- cHatis method
C creation of object: [reference
Vortfable)yer
QP Method with Hh Assumes 3
The procus oft erating method swith, rg vorfable to
Perform a iy
“Arqurments: Vettabln which carta datés to volo @ desl
sy ota: t t
ee ) eel
Arcos, specifier Accommodt rhs retumype nats Me (
Peahipe Apna 4 Bi eq: ]
wee the 3 tena
: ae oe ait 7 raping trom
“Fecal ‘aq thients: 1 Jos
} |
The arqumenk which aye eveated fn mothe stenalio|¢
| Gre known ai Formal avqumerts
> The arqument whitch aye | ereated aa mete” cil
Oe kno a Actual’ enquments ae
Example: ae ‘
Clam took :
6
Public vofd mi Cinta, mn by
§ eb
8-0-plm (a); Formal arqumente.
$-0: pln (b);
5 K
publfe statfe void main Cetin 1 argc)
£
tak by = new tuk 0)>
4-1 (10,20) ;
aa
5 Netial argument: (data)
3
re fl
— SE—————_ =s(i«(«(“ai ae
hod prsae
even odd i mat \ )
clan task : va) 1
t publ’e wofd tresiOr odd Cint num) Bic} ane ofp:
e ; CE) BO deem ro
. PL Cnumf. a= -0) . eotaddle 14
4 s.0-pln Creven’ 4° “A mum): (at
4 qa mea)
eue
‘ So. pln Codd'+” “+ euro);
ofl deipt Yra aye
1 ee be \ . eas)
public state vofd main (Sting T] ara
i tosh bps mew tH Gin fo acts a) on i
BD 41-ctendroald C125
ti even Orodd. (13);
ii Bae
IAP Creat’ o mon-stalic method ushich rtaker. in num
‘Cheeks whithey the num
prime or not
deiA- > Crat a maim
mthod amd call mon- ctntic method
for time by Pauing diff data
Class prime num
i* ‘
» Public votd prime (ime ain ay Binns
} ih o>) Prime num
tor (int? -@ , Pes num 344) Prime num 3
f : ‘
| x
tC numn)s a Nka Prime num 4
:, Not @ prime tum we!
ot Pome | num 14.
qe '
Cid tay
a 4 (ene)
| oa
| 8:0. pln Cptime num’4" + + Num)
else
.
So.plnpubie Stab’e voPd main! (thing TI ava"
a Primes risers." Piles mena prime. num
Pr. prime (2);
vgrRapmine (3);
Pte ptime (4) ; ‘
Pls prime (15) ; ‘ aa
Pls prime (14);
5 i
pried to prime me fr t to (oo 7 mie calling .: public. stalfc:
daw _toak \
x pubife voPd primeOrNotC fnt eum yo! a
: fmt c= 03 j h
for (fat 7-0; Pe=num ; P44)
t 2
Pe Cnurn7R= So) oy bes ,
¢ Biv ar
reg Eauie Ws Fan | ined
a as | usd n
% : is \
M (en =2)
i so.pln (Numaitate primes ig I
3 7 ‘
% . , a
Public static, votdy: main (sting 03 ang)
% b te anew taskeys ain
set i 5 Pe=too; P44)
f, 4 ai
tuprimeOr Not Ci) ;
q
es BoA Oe ee
uke, vl eles te Vi
| cag toe ) |
¢ public vord that int a . e Le
Tepe tock Aiy statements which fe pruent belo of the return
0 tlie
Kegee rd then » that Hameo; oll bf, Ubreachable, ttafemenle
“WRI ek error
€q. Clan relyn_1
f
Yond
en Cotsing 7 axqs)
re iat ‘
Vo :
SV. TH
: cy Error: Unreactabk Hlalemenl
So.pln (Hello "): tq FPrplr Gtgen)
Tetbury ; a
p S.0:pin (Hd; ")! or
Pwr (thing ty arid i
Lee ma
3 ‘ 4
2 :
‘ 1% A vot ily
veturn tupe 4 - 1
turn tup oe
2 The ype of data whtch fe returned by, the method
= we can return a data only by wing reluin bag word
J %
= =<.
rely Pet) .
vord —+ mo return value
fr > Prt value
double —> docble wvatlue
Chay J chaz value
Sting > Sting value
boolean + boolean value oy)
Type 3-
Cyntan te creat methods woth rete THe
nan cea poet
Iecew spectfien | Need modttier rete
nype rnethocd Mam Cap)
g — ova
\
return relura value 4 ,
Note ra a) tly @ Y 7
J retum value Tape # return lype should Be, te
ret value wofll be otuen +o method call b4
Wing that we com perform -further fark
Ex elad eqs wl
me cg 4 pl eae k '
b-8-Weisum (arb), ;
(iol 4 { 1
Linh c - ath;
Teturn c; \
ps. vem Cetring 83 arqe)
f mayy ©
Fok ves = uml (10,2095 6 ii
So-pin Cres): | + {
? ( i
3 k
ee) rauiean
Yr'- 80. 7= Fraram for even using boolean returm lap:
Clas eq
¢
Publ?c tate boplean
f
PE (num a = =0) ' I
¢ (
3 Tetum rue te
Wel owe os aoktyee ‘Brom vl
3 Tetura peter Pee
\ co veh 405)
pupiies. vim (ching 1 ange), Even 6
é é Eun 2
s Cimt P= 1; 10 5 Pra) Even 10,
PEC Pe Evenci)) ‘
t
$0. pln (“ven 4 #) a
RE 2 ‘ ‘
a
a ee '
a ; ‘ { Yeo) ey
ee a4 ee per
= CON Renn) fs¥ (10) «
fsEvenC1) aes efaem W\ Whaa=o
Visas Fete salel?) reterin set BD Ore ttth iet
wefiherts MAUL a TE CenS es ee
4 C fake) Print tee Bo
pie ies febren (0) han
Peo fe Even 0) PY.a=70 i
fsEven haa ee
Be 7 fale ft (true) t
Tetum crue WP Ctalee> i fe w) Funk :
print lime) Fe 6 FR Cony) lg
A ts Even (a) fs Even(a)
= 3 6%a=-0 Thass0
foEven (3) Tenn trie Tetum fale
Bha==0 iHCtrue) feu" S
aebnfalse Prnk
tFCtalse)-
foEven Cintenum),
hea
hE
ow, ree”
Moo for @ vetrrnlypds
ot ©
‘as 100? toa eclo metho
Seen Sem a clan + C7el
clacs ej
t pucife eqarte wold om Cink ae “ih
$ s.o.pln Cw method")
nun = 105 Ca
return P
3 ts
public static ft rige-Cink a, Bat bp i
ee iinh Be ake: ae
vetuin cs
Li (double a)
Public statf double % (doutle
‘ doubly (baie /250 aes | bey
Tenn b;
3
Publfe. Matte char Tal joe a)
f ft (a Yo 2 = =0)
3 Chay ch= ‘E's
4
elte
é
4
% Teun ch
chapj ch =
i a Stalfe etring 15 CEbting a)
. tring k
Ck. equate (ay)
f
vetum kj ‘
7.2
‘ 3 é
Public ctatfe booleam ag Cine a)
e
“Kiran”;
(aes)
‘
3 Tetum bu;
q__ Veturn fates,_ .
Pub © vm CObinglT y p
reg? aie methods velirn YPE
Fomos o> " usin
Prt a = ta (10,2) 5 aa: -Mamstrong nur 1
Sso-pln (ay 3 va i ' ‘ee
dalbte b ~ 5 Cima); Ce tank num)
S-o.pln (b)3 t04 t § pubife claife tt factostal Cn
Chay ch ~ %y (10) s
S-o.pln (ch); met fack=1}
on i . | f far nam et)" Bak 4
mq P15 C8 Kan") | 7 — tor Cimt Pel,
S-0-pIm Cp); Be ?
bpolean ie ¥6 (10) ‘ mt ‘ es far 9
Ssopln (ky; wt return fack; , ,
z. 4 i as. \> 4
2. \ hy | — publfo clatte votd shong Cint pum)
tL preram for prim wing booker «elitr lYRO | ie. ene) ine) 4
clan eq wes int N= num
< ; : Ho Unk Pex a
Parl stato boolean Ft-prime iC tnt num) ° ' whPle (mum | = 0)
¢
F,
imt ney \ 1 f imt de mum% los
ct PeV3 Tes mum Para) ink fact = tactorfal Cd); 1
ttn Pages oe SUM ~ cum 4 fact ;
§ acres mum Clam! wystver Uoateah arn becolt
, ercale m-%0 ap re
emethods
cobteh weal wot &
+
—> For an clan we Con 4
J Clau come? 4 uastabls and
+ Tt aul cm wth. bri "deo
4 thar tea when pub Prtio actron ,
usp nt, duim. ‘ : & “9:
+ Glhen +the blueprint fe implemented : & Ag,
“ You enate a neal prodyet
TE becomha om
bihen we eprak pm
Youa. this blueprint am ecter crear
by “Sh claw. ot '
class co claw Mobfle clon Lapto|?
§ i ; 7
ys ‘i | 4 3
: t
You mention what You mention what Vea wm seit
mentito w
~ COX needs to have mokile meals to hae
th then form °l\ fr the fxm of Laptop eek 45 have
fake ard Vantablea and
el hols ™Methodya OR
eget 5 -
ad " ss ée +: ' ie f , EE it offi) LE
Object Pe tnctana. of clay = 4 en it
= Obj © otatte Sti Kevan So 2 AG
te Ps weal contd enti tafe a tarnied by ti, pubite Ne rain (stoned aq) |
i4hey
> Evey . ‘ amin ofp: Keran Solank?
‘oF Ls
VOR Ker uti have 3 property ye Ae, ad: ier SA ee
fd Botewtequsld . hs $2" Kinna";
oe ; S.0-plnts);
| stata |/ data hvartetles 3
CP Mctonatiiy / method i
behaviour.
it a } \
i : a
cla an rarae | ae / 2 dudent b>
Chapt vata we ;
- Slaves wnt | otatfe shing, name 5 “Lan Solanbt’,
dats /elata / ng Soba) ost pubite, etalic void! “main [Csting fT ane)
Voxrasoles” Objet vars / ¢ { |
non !cidF¥e’ variatole shidimt ss mew éhuclent 095
Pods seit saad sludkne | pm student On:
i es wl” $-o:pln (er. mame);
p4. Belincnrctd ef W0 q pl
functionall 4/ Fe state methods 8-04 pls (226 name): Fis ay
rpethods / ettweine * eee! ‘fp:
behav four [: ny i IDeA
cele oye reethods / bio | j Solbha Chama rite dor Kuen Solanke
lanes aed p00 - estate wneshott 8.0:pln Co. nome); _ Kivam Stank?
J ae Naa) Kindotn,
7 . a kimne
Class ventables / clatfe varfables $- i Bret gun | : re | Kinra.
Cys
a thae aye the vorfables poohfeh ove prownt on creat / * icc:
yr \ Sta , tot '
frifde a clad by using atte keyoord i t Hie oe “vaitid in SP etna’ 7: vone
he is : ‘i r a ie Pint oils *
7 these. tcrefebsleeffl” be common cst Shree © Fobjcet create Pint nen ae
. clan rome Sa. object crcatert ae
hi ie salfe variable value efther C1 z
7 Tf we ¢ an 4 a Print sirname 7 Fan Solomk;
or by amy object ie tll effect. Covoclfrcaton)” Pink s-nam Fon Solon,
¢ fyrame = Kina’ « Charged in stati
daw i ene
aut the objects oF | fo at objet ¥ clan
a eeeIE Claw Stuckeot
§
tal
if te Strimcy -narie\ =" Bron Solnt"
pose, eine tt
fe
Stauic vata rain (chang args)
f
safe si eluclent 0;
gee ee mews, Chu dent () + ‘
ae eal’ i ad \
= new
SO-pin Grams" +3 * “Ly:
wage:
So-pin Cornamest ry ¢ My
4 2S ee
3 .
-Kivan Solant? a1
Kiran Solent? al
Object vaxtavle / Non!” Statre Variable :
— Thae
—> Then vowpfasles ou! mot contafn slatfe pet
Be object
ae vartiable, which belongs bow objer
> Value a Vavifautgle: ‘att fere from
> thee cam be accessed by wing Bbose var fab!
C Object)
.
~
> TH we chamge the vol of tr variably, wir bo
one object Ft wll mo effect ee ol ber cl pon
— ———_———— ties
BB sian student
. Stine $ sided 2" Matla Reddy” ,
int! age's ub
Proven (hing tI args)
{ \ {
student sty mew ata dent 0);
Student % = new student Aion!
s-o-pln (siomame) ; ( Mallee Ha
Simname =" Busy Kanna” : _ Mane Reddy
Bujjfkanna .
S10: pl (2 name);
$0: pln (6). mame) ;
3 096 = pag
\ae
oA
MOTE 3~
—» Tnttialfcation fe mot smardaton Por tae? or lon Uctole
i
var fables
S DnPttAleation mandatory tor local’ vasjfaloles
( Var fable prewnt Lemeatia Petal method aafe local
|
* way{ fables),
> Vedben . og bpeiEe Clan Tat
f
Statte tk a:
Statfe double b:
Stalte chasse.
State ¢. c
Statte
s
bovteam by:
P Sum Ching PF rq)
Pe ear bil
8.0. pln a);
S:0. plo Cb);
S-0-pln Ce);
$0. pln (gy,
3 $0: plncb,),
3
hoeal var{ fables t - bf
Thue ajé the vavifabla which MIF
oneatid
= toral vonfable cannot be accasd aubfde
ee 1
clase student) >
t
Fdc(dL. meted
of the method
+ far local vaxifables MPtfabfeation fe rranclatony
Q: war, for belowo ona
> Creal a claw,
Crate 3 mon-stalfe, vortabla 16 7am
; vosfoble valu
“Change amyor stalfe
7 \Ghreale a main method 7 encode three
object wrt Fave MS ow nam , age ¥ qt -
a4
+ Prrok variable
Cuate 3 ctatPe vor(Rabl: 9),
ai pet
ih
Mi
poem ( ching qt args)
f
Ap jiv-d UpARE” 5
T scyaetll ching Hn i
hh coyinter nth etre = FOF
statle Shing bY = “ECE
String mange j
fmt age}
choy genders
EG) 5 95
atudint sy nen clade Nig
Student 2 5 mew Braden O95
Gtucent $3 = neeg petulant 095"
tg ¥ wim
r oO
Bye mem = 4% 5
fa. name = Ntketh"s
Sage = 2a;
Soe gency «i;
fa.name =" Rerha’ 5
“eg skye Wai
| $8 ene:
So: pln: (alnames 5
8.0. pln (c).aqe);
$-0: pln (6) « gency):
8:0. pln. (62, name);
$:0: pln (1. aqey;
so plh Ce) 3
S-0- pl C66: genétey) ;
£0: pI™\C mem);
S-o:plan(bi) 5!Pri Ya hy
an — nome
Qe Create 4 non-chtfevariabl, s.o-pin Gere eng a
@ Carate a employe claw , Sep cea eee
9. eHale, | O° ane
Creat a main muthod , Crab’ 2,ehject » i f a g.0. pln C63: e- ey
State wrintiy w.2-t0 oby-ely prin! aul the Variable» 0). 1. oy G0. pln (eg.€-td);
Clan employee grid 5 4 ' ud
f : | . . ‘
: 5
Sine e-name ¢ wd |
S89 + ame
\
Pmt b_ , ;
String see 4 ‘a hae
int e — fadls yi
publ .¢.um Code. (Faw ‘ i a 8
\ gC Noobs
e ermploqer! a= ep eemphorger ( Syps
employee) > mes, emplogee (1,
employees 63 = maw emmplorpeet
1 e-rome =" Kiran". *
enue ~ aera - "at
a “Abe's
Astor 2 ay, f Shing mame;
C2 NG Matrmes Be Font" 7 Strymg_ color; i
Sa ile #28 doube prices
a aes String | meus ey \ :
€3-e-name =" Poa Stoing sprod } Ke:
Peblfc vord déeplay. 6)
: ne
£.0.pln (mama) :
CNS ae - ats
€3-€- prt es “gmy,
€22€-fd 2 yas
8-0. pln ( en, e-nany);
So-plm Ce. ¢-age);,
GS-0: plm Cees apy);
S-0-plo (4+ eta) ;
S.o-plm (e2+enome);
So. plm (ere-aqe): inetd ew pigne 7 4
S.0- pln (€2- e-pr});
s.o-ply (es.e-fd);
S.o\pin Colon :
2 Yin
£-0. pla Cprteed
BY 5-2: pln cram;
SO: pln Cpreey sName =a;
Color sb
Pra =e;
Ram ovals
7
PxS-vom (sting CJ args)
f
?
haptop l= neo laptop %
tne Fntt CHP," block”,
500d.» 868" * i");
ty Aeptany (ys
: \
Pe Gane lptoper.| vote intt (hs
$0000.07 “nea"s ta") ;
IL, displag ( y
t
r=
5
/ Sg eobreneeh si
/ louble pote o-st F000 A
[Shing Riehl wed; 4ove
/ Shiney procomeats i's
coe! dispaqisr +
ce on
void nik Cer -- 7
$ ;
Pubite vole frPt | thingy Shin b, clea c, evi, ¢
> Print au non- static
> Crratrn's \o by aH"
&
1 war
4 Creat a clo
+ Creal a oteilfe, vosiarle 4
for below requiterner
rain
' ‘
* stabe vauiablay ss !
- ‘Cota @ mon -static variabks -
_ @lass train
g lepine @\- "THaltan
Static ‘Shirl + Rarlwarfe
Sting ‘Train —rorne +
2.
Fite Train -nums
String color 5
Sting types fe
String maz. epeed + et
publi vord dds 9
hs so
ee ee
8.0: pln (OE nur; Moe
Lo-pln (color);
S-0-pln CAypeys
S.0pln (mor cpecdt)s
2
y
gi ar hon oh
(Fiajrn—rome, 03° °
Train - nur =! bs
Color = 6"
tap = a?
tar- speed =e 5 ;
i .
Public stalfe votd mG)
F ¢.0.01™ Ccompartments) +
2 S:o-bln(Rattways) 5
Cree)! disp
yosiaisiae ie”
atte tment = 185 ore
“gi od \ Rot ldor/s e
public void eft ( Shing a tric’ » Shing ey S4ing + Sheng)
ia anathod fo.
44Petum (Otring £1 arg J —_—_—__...,, c
t
l iu i} od
' SET Cole ei enn 5 Creal display meth
7 cal 3 Stal ¢ \
Bites: trig nten) detura ed s . SY te wee | -
' : 4 . states Yoriable. atria displey metho
1+ inte Cape’, "123, "Blu, Soda’, 1206%/5"); J Creat + non-ttabic vasiable , Ge 5
fed; . ' s Creat 4 objec
tram ta. new beings Pinch soe
tae mee a “ ne ve "
Ktm", 2" Yellow y pasungers “son tm /b”) 5
-— ' ‘ ckatte pak hours = 35 |
ta.do)s “Tretkrane's
avd 2 ' visit statfe Shing divcioy ae
t3 = new tained; ‘ State ‘ filrm—inchatry e "TeR yeep sq
tactott ("pap apd Ve ae » String Sgt +}
R's. #89." Gneep"s " pauuagen, »,"35pbm/h)s string ‘hevoiney \
tad ods ; Re Shing. hero ;
mOs oo \ i sting villain 5 vil
3 ie ’ int n0-of- soneyss :
z. Lovin! Shing. populat-fone &
+4 pons aa ‘i .
ba share [n String, covthedien ; pd Ve
sen Bring Train. rovme = nat ABC rl ibis toiling ype!
rie coe IC Gh Train numer id bi) S purite» ledabrel| Foi ;
Lat
€.
ia
String Railay’ >"Irdicn
String colov ~ nut Blur
stot tap Peay s.oiphn Rouwe; oo
s-o-pin Ct freetor);
Faitooy')
mo | Shine erat spel =D gD bmp"
‘s-0- pln Coompariments): poet Jue -F A opin (Hilo aiid ,
S-o-pln Crastiooys) a A | veo rain” Ce A
lla iia pusttc Mord duploy ¢)- a oe
somo oe aR
f e ql ‘
: Fee (eA th fat Cinema’ 4 t Waa de;
€ oo
af aot
Se
Booed sen tah
8. " spel :
: Sang Trainor: “att'Pae" opin CMowie mame fe! 4 mame);
© S\0-plm !
; qi
Trains a
Gt Trad num viege Ink Frcxin:.ruern> uh 4690 ; m heroine); «)
Sr aad Shing cob pac Bpeco? | eoetn oe
Shirg pe ie sbing TDs nut esr £0: pln et My.
” ies % May,
String, marsped= utente /y (hig ants pec sf "srk, $0: pln (> COSY Glgate
iA AC) ¥ i No of
ee Wid dC) OMG in moves + 4 gon of :
Sa 4 bangs ane $0. pim "hs + n0-of cong);
fa Putay song ef moyie, ©
Sid init © ay ett @.0-pln O" Comec 4 of ovies “4 poputay—song) -
i ea Wes" F amatian)is
2public wotd trith Shing Qa, Seta, sb, Stingee ; 1 tag 4
& int @ , nF ee String aA “
name =@ ;
hewoine =
hevop, See
. x G > nod
Villain = 4; :
no- of-congs = ei; i m4
pea \ pi!
Comedian =e
5
Peskin Ostong 1 1 ogi).
f -
movies M) = new mMouia eye ’ a
me an “ittora’ > Mla Prepniia “Soneesood
" OMadha', * Brahmanan dain") go.2
™ Apel “(or saath) eel) Be?
mouret ma = new mola CI; rl Re
? :
macintt (“Aharntel doa”, Pep } Nepeg tele |
o ee, ” : .
Rete ovfiia" & , “Aitou ehudegan*, “ Brabmarandam'),
ma dtpiog eas... Le Ee igh
Mouies m3 = mew moules C)3 myo -* am
mastntt ("otha da" s “Teche”, ~ mana bh" “Worutiood’, 6,
“pelichtna”
m3 -Atepiault a
eects” uw ey
——~—TO
su
a 7
2 Consuela * es } |
Te fe a ‘spetal "pe of -
me shouts be
any ote legpee.! |
To perforan) a, Tost
|
afte] ob 1 ch ¢ rate
Prinhiaq ,
initiatizalvoo
cal at BP Oder touk.
diss
: yeas:
Hole
> Comshucloir will be catted og ctunng obit ereatioo-
Clau exampl, =
a 3 P. ; ofp’
String mare 5 Conshuetor ic exdeusbing «
publfe example ¢ d ra \ Conchucton 7. sreeuting
e i :
a $0: pln (* conctuctor fe executing "5 ye
me 3 : me!
pesvim (tinge a args)
7 example e1 = New ¢2ample c);
s example @2 > mew ekampledys: cycle
A ie
String Tame¢
publfe cycle ( etna a) |
re ey
mame =a;
3 So Pl Comehuc lot exeouting 500
Pub iter vod’ dicplae dy
tr
a
P-s-v-m (Ching ty aras)!
iS Sol
°
&.0.pln (name); pelo ies i)
mew, cycle ( Hero");
Cre dteptanyey; i“ 7
Hele con's mew cycle CY Ldreulus "5
Ca. te plate; votst
Shing samteaech
exer Cotingay Mer?
nam-=a;
qe
told dicplay cy
Ya ie
eonetuctor executing
kro
conshuetor execaling
Hercutus. pee
- aaa \ 4a
qa: cine fo below reqpuiremer
= > Create a claw ¢o- hi
4 Take imon—ctathe variable ae a
+2 elatfe voyfables : 8 cteucter
+ Tnitialize non - static vniable | by | ps io
‘ non
+ Crate g display methods for en vente elt
+ GCreak 2 object. ray ae
clase coo
SHtodiie—'
statfe oe ee ls,
_ etatfe mt break = 13
_ Sato gmt speedometer = 15
sting eames uae
ston Speed ;
Int wheels 5 / Ua
fot ndofdoors $i i) eo) 1 , %
String Fuetepe 5 cd apa
Pot capactty 5 ee
punts a2} (chring'a y/Ching by Pike pinta y stings) int #)
g . 4
1 cname =a35 ( ; wk i
cpeed = b;
Wheels = c 5
“noofdoors = ds
Fucttype =e;
Beliog APG ae a 4 i.
4 Ht
Publfc state void dc) eS
§ dow
Kos eh fi
S-o.pln (staring) ;
& S-0-pIm ( break);
$0: pln ( epeedomekr?;
5Puol& votd di 1
; " a
S.0. pln (cnameds,
S.a.pln Ccpeed)}
S05 pln Croheete) 3000:
So pla. Croofctoors) ;
So-pln (-Fustty pe);
$0 Plm (capactty) ;
a
p-s-v-a Cehing fT arq ‘).
ee
t pe
66 fay eet ‘
oii at otal nal bE "eee
5, ‘pttel', +);
ye di O) 5 (
Car Ca = new coo (" Kta”, “150 beo/b
& died "» 4) 3
C2. dildos
(Car, 63 Fi menn cary Cf Breea” 4 M4ORee/ hs:
1S dttet 5 4),
Ca. di C35 :
2 aa;
a.
x Tht (keyword: pe & a kupword ohtchi fs deat to
currenk Geyer object
4 the tak of Ante eepoord | to sa ‘curt
ut referenee variab
oe
Note tm Wy tH
pees :
SS
bthy we need t
=> alhen soval veanfable ob;
aye same, ‘if qou goamb, 10! a
ond object varfabl name,
arn wet waite fe
oa
we need +to we thie aly eo0r
“synay this. varfable-name.' " ' ee :
'
ef Pf local variable g cla 7
Vadabe namu oe Lame tinct prefer 7
be Jive, to focal variables. (at wie ine)
i variable oy
Ey claw stad poly
a
Sting “rome 5
tnt ages
public student Céhing name » ring ont age)
r 4 ™ 1
"Tome = name
Age = +
a ee
Public vod dlspoy o
: BA da 4
8-0:pln (name); wy eg
$-0: pln (age):
4
PS.vim (String (J args) {pos
Ei lag, \
Student: sis new, Shudenk (* Kran! pat)
: St. display cr; :
a Wid hicphy (>
* sopim’
ge Pimcagey :* ve aE meted © edn
Claw ctecent 4o oreall & ae voto 4 » Gals wie.
$ of a: WAP 2 si non - statte au o-s vast method
nigrane sod? be loanig we Ce att asi PaRe |
Srirg rare : Ktran : word ee sre
int _age ; ai. ar Use ante Ped Greate a ean
098 5 ) \ + Cxeali & objec - % ghee |
abit Student (stn name Int agp4j 00 0! | vs A :
t ~ claw metro wet :
° : Lp re
thicemame = name 5, ld 8B tiene Kido f { “ito | j
tte. torah: Yok age =07 a1 NY SHying ticlek + - (gon ah? TUL 2 «Lan! }
3 oe odes 3, Babes etadent Cobia rom at ey) ching ues) et a
: \s $ Y gape
Public vod dt) tea Shing) Card 3 va ver a
; ‘a 1 ok Stret SHIEY iycn - ) cont
8-0:pim Caamey’s Ful atid 40 String ond joc bo 1
Sopa (agent Soph ~~
x 4)
3 eS he old
7
Pp: S. vem (hing ia] ara)
t
student s =
4 Sede); a ; be tng
BQ can thadmt
£
Stitt
statre Sting mame 5 yp
Publfc ctudent (¢tying name)
¢
S-0:pln. (ctudent. nome); :
5
presuem (String l) arqpS'\
i cae eed
Btudent- sts ew" Htident’ (“ Kekan!) >)
aa \¥
r 4 :
mee student (" Ktvan" 31)
1
z Lf nau: . wah
Be Por ‘
ripe Mee P giccusiosk m1
Lal Tek (sh Hebe, mg lite Ching ord, Gpirgactos
wa Shing end , Shing ccat)
ml
t
Shing tidak 7 neet7ean
String Unt = neect7red hire *
Shrine) cand = bat ere0
aaa ie aude
histfeler Sere wa ;
Yate. Line = Kita
Shing cnt = pud®] "LOrage 4
Ate id= ae ae rrled = Baas Oidipan!
Tastee &t : ‘ching echt tects fait”
ee Se. publie mute, * (chirg eos! -- +)
trfeveddk Scat; | ea adhe
3 sh 30 1 25 !
publte “vor Vd)
f $-0.pin (Ye og thie tlcens
So.pin (hing) NE ee rene
Sop Cae, \ *
MO-pIN (chewty ; 5
£-0-ple (end;
% SO: plm (cart; ;
es. ;
y vem Cotmngrs erren) ; : ;
meh my =new mebo (* cand 5 Sed ti
ve actih
md ();
iorloslror 2.
Metho thod Oeeelg o
> o 2 NAME!
h v0. thi with eame
i Pp cul of creating a i od |
‘|
Gr but fin different ao- of Agito of pe Of cxsqurnent
— fe depende on
“> methad name
> Arqument
= PE doumrt depends om,
> Aceem Beuhyee
noth
mn
vi
> veto rion | '
Eq: clan demo ; |
f me
public vord ™m) ¢ )
e ( x1 O91) ty ye Helo dora
2 S-0.ply ("Yello"); fetta . 4
ok A A}
publ vofd ™ Ciptay i | | aek domly
SO-pln (PHetto Ds. Gorden 09009
es >
psu (Shing td orgy) ws
f 7 os
demo dj'= New demo t)s
demic);
dim (10) 3
Wh, mi Cinta 7
Wes ay
he
my
3 C60 ff ett Yn x02)
ay clau demo © ‘
publi. vod tm 6 ia
Seo.pln (“Helto");
public void am (mb a)
e
j
Pe ts
¢-o.pln (“helld");pustic vofd m (Fab a» Prt b)
fe
Pr Sven ching 1 axgs), ’ |
T> sa in WaamaprA aon 7
demo y= neo | Lae Oy
dremitys
diem, (103;
Soptn (“hu Od: [+
3 dium C10, ibys
4 lax operodjons
\ 11M
t public voed sum Cinta, Mtb)
f i 4
S-o-pln ( Sum "44 bo)so00 |
4
publi. uotd cum (inka, intbitnt ¢)
¢ i
* S-0-pln (“sen fe 2"4 Calab¥ cd)!
Publfc void sum (double a ,double b)
° eal
S.o- pln (“cum fer" Cosy;
we 5.
P-s.¥-m (Shing C1 args)
$ a op
sum (10,10) 5 do
; 30
sum (10, 10/10); OER
Sum (1g,0/100+1); :
5
4
Pj, |e Cellaading 20 jon meet ;
Het A
A - lau operations x ( \ i " \
‘ec Le op
mi ‘ polotte ‘kate veld grog" ss
jay? meq PO
eer ae $ 0. pin ce « OUerloaded re! ,
' . ee \ eat igs bs
anys y pap etattc voewmnarp Cet EGES +
| Ine. ¢ r
main (10) > lk
3 ae “yy
3
Ofp.- Overwaded “main emethod »
\ 1
Woq a clan epesaliom ne yee t
pub static vod mi ge a
y eed \ 44 5
TAuUMeny
7 | é sonpin (othe fs amy method WHA roy O7F
j ral | ,
oe publ fc votd ™m, Cfnt a) @ ‘ ;
: ¥ + > wt
, ‘¢ epi! ?y \
en ‘ “UL eb’ :
: S.o.pln (“thie fe ant method wof4b een ears
sae ting "); ; ok
4 yas how
‘ i pov mC String TI] args) Bie
TL ‘ operations a, = mew opmatens 69!)
> m0) 5
Lslooy acl
~ ' Oye C10);
4 4
op: anv
Thte fem, method with no arguments. )
The
f& am) emethed eotth Oiquinen® wth over loader.* Conehurctar Ouoploacling
Ye daw camay
Y String name:
ing
werito dlift- mo of argument py. a
JO Por conehuctay Overancg. this () t-
pang “dances ¢) > Meneed +0 40 fos con
S-O-pkn (* when objec fe crear wan
OPI C"damay te creatid"); "OP data 2, hd
. Co ead.” ) ae FOr go,
public ore ching ram), 1
$
HP. name = name:
’ B :
Public danay ( String name, ont )
é ce C String has
lh «name = name}
thit-aqe = 3
3 Ts ann
prseeem (sting CJ arqs)
£ v4
dancer dp = new damay OMe
Anus Aidt neariciid HO
dana dr = new dana (Ye ran") +
do.dco; )
dane dae mew dana}¢Skivon’, a) 5
d3..4 69; ¢ F ay Ney |
5
puslic veld dC)
£ e-o-pln (mame); \ \
; S-0- pla (age; \ + In one dau com ret Som times i
mm one
ms no. of camchuct ors.
> Te whit used only
yy A
P arqaments ”
utth 79.9]
FTP murtfple conctructors ave a :
oo) nh getecetaut ; - |
IE we using 4nteO the mo.of Srqument posing: fo te
the that eooctuctor cael woflh be Bebe
> TH thoutd be Pr fist Lire of, constuctat
. ath ow ii ’ : i
Sy class customer C ing tg oe ;
; '
q\ |
\
Le
Vig? o
publf customer Coting mamertt age , Chev| gender)
é thee Cmame) \
Abit. age = age;
, hte. gender = gender ;
publfe curtomer (Shiva name, It age» chore gqendin » tk
Sting addreu)
this Came sage 5 qnde) ;
this. aadhoiNo = dachayNo;
2 thit. adden = Address 5
,publte vofd dé)
‘ S-o.pln (heeliiante) 3
SroapPh (4hierageyy ay
S-0-plm Chie. gendes) s
8-0" Pim (thfeadacthaxie) 5" 1
ae Pa CAN « adehen)s
+S. VI CString F9 apy” yok \
nye
customer c= io Pir: ¢
eye AEF
Customer Cyj= meu), cuurtomes GHeena’y 21 923!
Ca+de); : Oem
o Ctastomes (Shiegy nye |
na choy) -P OKIE customer (String fats
custom} (Stig) inty hay) nk, tring) 904 13
Tigers ca ae singel CRIA SAT ogee
a Wid dO 40x29 ud
oO, :
nee 4 .
ujje os |
oa Al
FE ‘ \
123456 \
Sanfochnagay
aS"
“Tne rience 5
RAAT
— The proce of crepe] ? ey 2
anther £la” feqkroseas an, eta i:
t py » a we! 8
‘ J al ye aor
» x) pes of detvirg amernbers
known as inheritance
ae
: Sikes ane Ba
Supe cian / Faggot las +
subclad Pe
op
soy
- aperbeed oP dyrricia
,
x al
a to
claw to
abo
& ebooles te |
sank
ae |
—> The clas -from whfch ven Sh Ae
Super claws 7 parent lan 7
Lub dau / Chiidiclam 7— | the
m
— The clax to whfen detived ™ b
Subclau / child clas -
ov
the cout +0 whith members
Gi \ > A ( supey tow )
Dipdriad? \ 7 Clim
; 2 (Shien) yeu Gabi? (el? ana
Th mbejftena 3—
i a
eS hevel Tnherflance. 4
BOUL? Level To herPtance.
) 7 ‘6
8 deranitelttanertane,
4. Aibrid Tnherflance .
F. Cluttiple ‘Trhertlamce. +
PO fad wae
t ,
ake qfven ft knoxon as |
} oly
di 5
unl ong. ve"Sica ~huel Lnboithane 25,
2
— mame which
| Ly Fle name should be same 24 clart F
Dennen 3
“ \ contahe Amatn method,
The procon a amnot from < eh Gupor —~> Objeck mostly exated for cub cau:
ni eh im a
PM sub clay fe brown tt - level Fobetlay, =r ale cam creat n-n0- of aus fre:
t
class sarmple¥ kup cles a
2 toe ai cory, ag 2
Public vord omic) ro .
i wis ae ¥
S-o-pln (thts ‘tam mélocd “op: cam ple) +
%
4% mer Ab -sel al ws
claw Demo extends sample |
¢ ™ subclass. sre 935 ga ail aly ee "| }
mE & = 364 ty. |
3 7 Ses
claw Caimclau wv awt i
i (Cte )
p-s-uem ing TJ args Ca
? Demo dj = new Demo () 3 '
S.0.pln (dy.a); -
S.0. pln Cai bd;
2 diem); ee