0% found this document useful (0 votes)
14 views

Constructer Java

Learn Contracter in java
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
14 views

Constructer Java

Learn Contracter in java
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
| Java Constructor Constructors used to intlize the state ofan object, ‘Constructor must not have return type, Constructors invoked impli, ‘The java compiler provides a default constructor If you dort have any constructor. ‘Constructor name must be same a the class name. Called, Te s_—™——“‘CSOMWt:C*C:;:*:*~*” Ln = en @ 4 Constructor in Tava : F -— 2 Th Tava, Constructor is a block of Codes Aimilax 3 Ao method. It Mame Aame Qs Class Name. Tt is Coted When an } j i 5 Memorg ie altocaret don Pewee IE Cared and 7 od Atlocatest tox the Objeee. TE js Spetiag 2 *GPE of method sation is Used ts inj tot ‘ ; Cots ee i i fia tne db pee 2 — ot om Objet IS cHeated Us} 4 Odleaste one Constructan je v : nes ct is Catlnd dejan Types ca “tte 4 Default Constrvetor 9 IF-there is ra ; ©, Comstry ctor Z niangsmne (non Pantin Sie Pea lee 3 Form etd Cons tructanzTe je Used 4 \ 4 Coby Conserv erg labtth ¥2 the. disting. Oe MiP Ferag Java Method Method is used to expose behaviour of anobject, Method must have retun type. Yeron Method sivoked expt Method Is not provided by complet In any case, Method name may ot may not be same ss class name. \ \ a © scanned with OKEN Scanner Constructors (6 SE 3 4 Constru ctev mame Class mame Should be ane: % Constructor have mo Hetwn Crest a ES RE 2 Npes af Con sbroetow oO ea ol Defoutt Construcren > > Without Pararattrised Constrector “ease ged Constructor - Coby Constructon_ Syntans Constructor name () & 3 7] A. Class tons “8 a Cons C ) WM Co "1 : Str chon, having no Rarameren, ¢ : Yotem. out. bainthy (* ; print Sefaute Construtta,’s, Weid Show C) é Syctem. out bomen Uo Hate"); Si i Class Master h é public Matic Soid omoin (Sting oye) Lb 6 Cons che mew Cons() I Catting Grestevetor i CA. Sho 0; j 4 7 3 © scanned with OKEN Scanner Class Cons g nt 7% Cons (int a) lr paxamnetviged Constructor. He OX’; % Noid Show () System. out-brintn (“ane = "ab x); 3 4 Class Master & public Static Wold ynain (sting axgct'3) é Cens Cle mew Cons (10); Ncabting preemebijed ont C4. Shee OY, $ ry tam — © scanned with OKEN Scanner Constrouer oe Ta Cy Constructor Overtoading in java is a lechrique of ve! mou thay, One Constrector With CU Fhesente Pasxameten St. Rach Constructe,, Perdomo Clb pewee tas. Th, Atpeentiond by tne co airs oo ™pLE by -the numb ow a peux a tht st and then type mae Class Student int id; Sting name’, Intage, Boden Cine i = ideis mame = $} » String S) Student Cine i, Stang S, int 4) 8 id ei; Mame = S) “55 oid display: O Systern. but: panel ("Toe + id); System. Our. prinln (" Nome >"+ name); Cystern Out: Printin(“oac."+ age), 3 Class Hoste é public Arotic Ahold main (stay agst2) SA Raekerse te © scanned with OKEN Scanner Student Sic ned Stvodent(4, "Raman" ); (9) Sivdent S2= MEW Stodent (2a? Anyan" 25); Si dishlog Cr, 4 S2- display Os, 5 Oiyeerte_betat “1 Constructor ama_metheel tn —Tayq. ee Ca © scanned with OKEN Scanner Coby constroctor- A Coby constructor is a Constructor that Creater a Te Objet Using an ereisting Objet ok the Lame clos and imitioliger Qach jnotance Yasiable ua Newly Crested dejeck with omresbonding instance Voniahte of she, Cubiting Object Parad antumenta, Ww YS He Coby Vatu of ome objenr into another ™m yava. ° Be Constw co Clars Rectan . i int Regi, J breadth, Rectangle (int, Xs ing b) eng eh; 2 byeadan= bo Rectanate (Rectangle obj 5 "ty cctomgle obj ) U Coby -Construcroy_ engin = Obj. engin: breadan = Obj. beeadiin: » Noid sea 0) e int A= Length % breadth 5 System out-printhe (“Ans "+ A); 4 Clast Amain © public Ktatic Usid maim (Sting ayald) ary RA= need Rectangle (Spl); Rectangle Ro = new Rectangle (Rt); © scanned with OKEN Scanner

You might also like