0% found this document useful (0 votes)
11 views11 pages

Java Object Methods Explained

The document discusses the concepts of static and non-static contexts in Java programming, detailing how these contexts affect variable accessibility and method implementation. It explains the initialization of objects and the use of constructors, as well as the differences between static and non-static methods. Additionally, it provides examples of class structures and variable handling within these contexts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views11 pages

Java Object Methods Explained

The document discusses the concepts of static and non-static contexts in Java programming, detailing how these contexts affect variable accessibility and method implementation. It explains the initialization of objects and the use of constructors, as well as the differences between static and non-static methods. Additionally, it provides examples of class structures and variable handling within these contexts.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Jass L

fot a =12
5
5-0plo ("IIB1);
5-0pla ( " I I e 2 )
3
5-0pla( testo
eeeClctec)
3
test 2() Peblic
+estc):
5-0 pl(test2
ejecte'
Metno
Pe hliG voi mi)
m
aqe Ho

Dale YOUVA

Pyoe3 Contet
Cbjed oodng
is a pooce3. o6 Contet Hro& 5y0onym boB blok
cbjrct Le aclin9 no0-3otic membee
le he
Lencing becp a e a In java Cwe have maoely a ypes o} (ootet
th: objest

ohich
Coreieercto i5 a
comporent peyomy
( Non - 5teHc conteot

objet loaaiog process


As a paset ob non- 3 t a t i c 6tatic Contet
(oosteu cto
vatlable
block cohich s neeteo to
Object eOteol toe the
member} , gtetic itaiet b1ock (616,
Sttic methoos

F'! -te rbn-slatic methools fmplermentat


Non - taticC conteot
rolementetin Tebet ence Teltec
The block eohich is eeetecl to noo- 6taicC
metsds ianatee cwl be loeoleol iniole
objet toe a Uo membee Loshene initialiree. block (TB) >
Non-tatic method ) consteleeto

ror-statfa iptalice wi be
Oected in top to botom oede?, ko eaob
Note Losiole ny Statfc Context i we
oceessinq ary vaesable 'ee cty
btee Loaoling poDcey is completea ?+ hecks |0Cavaejbles

|ocae VaeiQble
vaceiable v alle cuill be given
the objert preet
q 3ttic vaeIable
Otihee wiSe. j chcck
Page No
bate YOUVA Poge
YOUVA
E
dass
class
4tetic. Steing 5= "Helo"
J2Stodic context
6-0plo (5)' /i Hell o
Dubc void tes1 1(
pubie dtatic voj nauo ( Steng c aeg)
30 plo (3);
Helo
[Link] (a);
3
No te Inside y non-stetic. CoDtest î cwe tey
-to acce33 vasesable dieeotty, iust it will
therkg toe locd vasela Je.
Locod vaiable D1th thot S obj
cume
poeseot thot vasejable. value, wl be
dtetie
vaibe.
D o 3 e o t jova. tohich daßs A
pacclekinool tot ad obËe ot chescone

Slors hc. CLccont objec


te hich
peblic void teyt)

I2ren 5-0:plo (r);


b-0plo ( this. x);
DOre

hgnest poionty coiy


psvm (3Ja )
(ora vasei able, .
Dt to ace13 non-stetic vaeabo
ro9-3lotic ontes, we
ra

thi
!:)0r whih s wjed to bol tho Y 400
5-0pla (x),
5-0ph(i hisx);,

xo
|@or) metd
fot x IS; this
1

obj1 . testo; obj 1 @or Heayo Piclc

tecle Ateq
classAle

l'ays No

Puepose oh using Parramteiee Constructoe

clos Ermployee
3ksog name
iot opid;
locble Salat;

Ermployee

cless Ermployee pive

psvm(3tJ a)

Fmployee
Employec. e9 = htw Emplayec()

[Link] ( e .nme,) Mutl

s0pla ([Link])' 1O.o

osha
ccsali
durtcirg ihe thjtcl
niliairiog the tho- stetít
the lon - slaic
ioiiíatierd al
prrqoam
he above
is pot bcing dehad} voawe
oheo
initiling Eroployre el =r,ess Crplsyeericho , 24.1333
leng the rode
[Link]) [Link]
constou to
cte
we cos
[Link] (el. erríd)
ncetpt the va lres 5.0:plo (el. Snlory)
Hhe Jon-6loic
the ioe ob 3.0-plo
5-0-plo (e2. e mpid)
5.0plo
int esnpîd,
Note As pee the coropay S1anda ohile
deiinging the
frralbyee (saig tar,el, int ennpíd1, nt 3daey1) he loca va
aeqEt ob +he eonstelr ctot
SCme Non- s4ac VaspjcLble
narne1
crrpii efopidl
Cmployee (steing name, int empid , doubie salay
this
this. empid empid;
ths. alasey 5alay
3
classmalc
M1
cssmte
Page No

YOUYA Page No
YOUVA
Dat

ctea te io leoyp hrea class M


okjecl
evcy iceral Rebeente tooard
6talic
iot b 25

Vatiabes

5-0-pln Co),
3.0pla
M obj= new M0

[Link] (M.aj5 Hecp ARee

muno|arca
s-0 plo ( obj.a , HIS
5-0pla l obj.b), I/ 25

methool Aeg
clAssAAle
1age tNo

Date

slalie in statc.
«balic
b}ufng on sllíc. mermb0) in s4aic.

Iy using objecl Resesene vnsefa ble


contet clo3s B
membet in a slatic E
usina alatie
int x= 34,
s usira obiect Reek n te. va& (Not Retomendos) publc void test e)

4-0plo( obj. x) | sing


5- [Link] (x)
b--tplsobj test
5-0pln (A-m) obj test (
Aobj = new A (3
[Link] (objx) obi Reb /Ct
s-0plo ( obj- m)', obi Re</oe
lassmute

clAssnate Date
Dan

YOUVA
YOUVA

using 4tatfe membe s3 insíe on -slatfe (onteot


b

insíde a non -stetic iy directy


2y classnome

3y using this keyuoe

st'y Ex lass D

5lctfc întx = 45:


public stetíc void m19

5.0pln ('m1))
3
7

pubic voidl tesl )

PsurnlSCIa)

L't oel ibb Non static membee 4lahc nemb)


YOUVA

You might also like