0% found this document useful (0 votes)
16 views5 pages

Java Exp 4

Uploaded by

thekurisuuchiha
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)
16 views5 pages

Java Exp 4

Uploaded by

thekurisuuchiha
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
You are on page 1/ 5

X. I. E. Expe Page No.

Mahim, Mumbai
Date :

NIEXXIEXIEXIEXIEXEXIEXIENTEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXITEXIEXIEXIEXIEXIEXIE.
KIEXIEXIEXIEX

Am Wite a Tava progam


cOnshuctor operahon
DTo shoinihial balanco.

Objcchive_ To heate anduilize a consbuctor in


a Java class named Bank' to initialie
et attikoutes upon insantiotion. This
prae helps o ensure that obiets
a e chaated with valid initial valuos,
improving Hhe velialility nd maintainability
c Hae cod. The obcctive is to denmonshat
how cons hutors c an be used tD_utom ate
tae initiclizakion pocass and nforce
Consistncy in doet choation,
Theory Q.i. what s constycto. List doon
Ans AConstuckoy n Java is a Speia
method tHhat is calQod cshen anobieck is
fnstanhiatd. Jts pimany pupose isS to
Snihializo the nuy ceakd obccks. The
conchuckor has to son nme ao the clasS and
does not haue a ctuzn lype, not even'Void.
onsuhozs in Daa
ana ho main yper Consbutoas

. Oefaut consbuu (No - Argumet


Cansuckor)
2. farametiod Consbu ckoz.
consttor
vhosked)azas class
ucto sault
conshuchors axguments,This
vales
that Tava
daf is (sbingC] Some
choyconsthea ("Dog
:No.
Page
povides
no clas, a diteent
:Date
canshu is ho
9E prinknman constuckuy
Constuckox
Paramehized
arguments. aYg
Types Constructor
Jelait ho
a utomahicaley vard objects
morf initalizedith
is n out name
iterenk dal,inod stahe clars
Dogi
onsuco Sustm. or diferant Sing
witth
any
eomples. Dpat
class Dogco parometnieed
publie Ono
plain expliciky
take consbuctor 3
ault complex
Example Example
Hhattakes
allos
not be
92. da
Ans docs to
A
is A
X.
1.
bo
Mahim,
Mumbai
Mahim, Mumbai
Date :

IEXIXIEXIEXIEXIEXXIEXIEXIEXEXIXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIXIEXIEXTEXIEE

void displayt
Syatemout. printin (CDog's nome E"name

public stahkt vod maun(Sbing[1 axgs) t


Dog dl=new Qog"Buady"),
Max .
Dog
didisplay)
d2.dsplay,
.3. ohat is canshudor overlo ading ?
Euplain ft uoith eample
Ans Conshcbr oexlOaduna in Taua is
a concupt hoing mor than on9
Conshrucor aitn diffeeant parametr iss
in th Same clasS. \ho constcors ar

disinguishad by Ws nwsber and tapes


Gpaametere
Example i
class Oog
Sing naa
öge
Dare ="UnKng n

3
Mahim, Mumbai
Date :

DXIEXIEXIEXTEXIEXIEXXIEXIEXIEXIEXIENIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIXIEXIEXIEXT|e

Dg (Sting n, inta)
namen,
age =a;

void display)2
System out. printin Dog' nama
taga),
3

pulalik stahic void main (siing [] aros)t


Dog ldln=e e
Dop d2
d2=ne
Dog ds- new Doa Max 5);
ddisplau}
d2. display;
da. dudayO,

Sn tho example aboyo, tho 'Dog class


has thte consbuctosi
LA daault constuctor oith no poaumeke.
2. H paYamknzad conshuctor that take a
Singl 'shing paramekr.
3.4 parOMeted conshuctox that ta Kes
Shring and an'int' farameter.
A. l. E. Page No. :
Mahim, Mumbai
Date :

IEXIEXI¸XIEXIEXIEXIEXXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIEXIXIEXIEXIE

ConcusionJhis Java pogrom Sinulotes a basis


banfing ystm, alousing
monewithdrau fund and check thiy
balane Jt uses a consmcto thoin ibializo!
the accont balance and methods ko
hande diteaent banking opexotiors, making
tae code modulax andeaby to maintan
Thoough
elstic
inputs ,tae pogzm pnuica
and intrati
enpeienca,
retivel dedeimo nshrating encaps
ay bieck-orient
uation ond
pgram naing concapts liko
initiaizatio

You might also like