0 ratings0% found this document useful (0 votes) 328 views6 pagesHandwritten Notes On Functions and Methods
Handwritten notes of functions in java
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
Sista Functions Methrds jo Travel
¢
F “
unction,/ Methods (in fora.) ¢ ©
oA method is a block 0 code which only Uns .
when i & called: Ps
* Te reuse code 3 define the de ovice, 4 We ae
many times. e
«
é
«
«
G
q
«
4
c
4
i.
{
{
/
this method MY method ©? J dete
Yyutar: net howe a pes UAn value
public class Main t sncvae of method
Btatic veld myMetiool ( oe
// ode
ig
a
public cous Math £
° access—rvdiifier sretuan_bype method () 7
// code
3 vebwen Atatoment; by $end
} here
a?
° method Gn) a ee
bona ¥ function
o wetun— type i—
A eben utatement coutits the progsam contol
fe tromfe. back to tre Calle of o method.
Un ale type may be pacnilve type ike nb
» 0% word type ee noltaiag )PT =S there ate a few Dmnpottarc things to unclorsternd
— About arekurning the verlues*
~~ “the type 9 Sta xetuaned by a maetiech must be
pe tompacttble with the ‘veetwen type apecitfied y the
Pe method -
ee eg: if, webwur type of some method % boolean,
pe we cannot retin “an integer.
Be 8 the vatiable wecieving the valu stunned by o
a method, must abe be compatible wily the 3
~ “ype peciPied fos ‘the method
~ = Poss by vabhe+ get
~~ 4 ae main () £ nome
‘a name = ©); Loe
= ; Crating ; guett (name );
= a
ee® voles ab =
es Site greet (paar §
> if = nena! pmt(naam)
CF ted vefereee
psvm () (
riayhe "= "at"
chan (name),
pant (name) ;
‘
ene
a®>
(Cnacun)
noom Ok
*. Ait chris a naarn (6)
crane ft ge ag 38 pe
chnnee
Lae eee? YY YOY Y |4 poinds to be noted: ‘
ie desnatoe eal ape Like int, shove, cho, byte a
‘just pos value
200 obfect 4s (ae
pang woe oe
gaaeeananner ry
ie aah alo but nok
b=a0) here,
oP ge b—-1p
Swapla, b)
3
Set (num, num) §
| Suey temp >!0.
ee rie num!) 326
hum2= temp; nume-stalt I
J ‘
By “2
# i
DPPDAPDI DDS
-L* 5
aes orn —? Dy, 2 3,45)
runs
eka! | [row the value of fits In
ae os 2 ond irae charges
RK yah 9
axe [oJ ]
; G5 4 Can 3,% Sh
eee reaX oped:
{de a method /function cope
ion ‘
Vourtables * cleclarec ira
rt be accessed outside,
(means iste method) con
the method et
Spee — atblinr cds Tne Gr Mone
Ga :
auty{ prorttey
© block (cope: Gat Bi “eutside
me +e
psvm ( ) c - ie
i Voriable, initializ
int Be 105 a oubide the block
tnt "b= 20, can be
© inside the box.
int a= 9%
A=100;W |» vawables initialixed
intc = 20; imide the
@ Q Cannot be ui
mt C= 195357 oubide the box but
a can be reinitiolized
5 a outside the Work:
WYUUldwWYwwWYUHYOSOCtTGCGCeCeCeeeeoeucoe
Variables like “a” here, is declared
outside the Uork, updated mside the
block and can also updated oubide,
the lock.
. Leop SCOpe *
ae declared jmide oop poem ane
howing loop spe
ve Ve Vs Ved= Ahadewin : =
Shadowing to Java is the practtce of sing viele,
th Owila ping Acopes with the same hame whew S
the veutable” in ‘Low-level scope ovewides the Ss
Vatable of Wigh-level auspe- Were, the variable ot 3
high.- level sc8 pt, ts shadowed fy tow- Level ope 4
aricble- ‘
eg? public class Shadeumg 4 ° ;
datic tit ~ x= 10;
psvm ae rw
System-out.printn (x); bah 7”
— 5h high- st i
5
AM. ©- h i -
arene es as
j 50 © Acobe
> Vordable Piqunertss
. Voxiable te wed, to tare a vauwable
number 6 O04 » A method that take
a ee ae pos ba
vexaxgs “methid.
Syntax: a ne or
peo static void fun (mt ..0) f
1 vated becky pees
s
Here, poasnet would be Pa 0| ‘ape ites