Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
20 views

Class in PHP

class in php

Uploaded by

komalshindemsgcs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
20 views

Class in PHP

class in php

Uploaded by

komalshindemsgcs
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
2) Write a PHP Script to create a super lass Vehicle having members Company and price. Derive 2 different lasses LightMotorVehicle (members ~ iileage) and HeavyMotorVehicle (members ~ capaeity-in-tons). Define 5 Objeet of each subclass and display ‘details in table format php class vehicle 4 Public Scompany-sprice; public funetion _eonstruensa.sb) { Sthis>company-Sa; Sthis>price-Sb; ) ) (lass Lightmotorvehicle extends vehicle ‘ ppublle smilege: public function _eonstructSa.sb8o) ‘ sis scompany=sa; Sthis»price-sb: sthismilege-Se; ) public funetion display ‘ echo " ‘td>"Sthis>company.td>td>" is- price “itd>
" Sthis >milege."td> compars Ssthis>price-sb, sthis>capacty=Scr ) public function display { echo “ echo *" $this>company."
“Sxd>" situs proe.fd> " ste Seapaciy: echo "sitd>sitro": ) ) Sobl-new Lightmotorvehiclec Maru;200000,25); sobt->aisplay0; Sohz-new Lightmotorvehiclet"Toyota’500000,20); son2->aisplay0 Sohsenew Lightmotorvehiclerskoda’100000,15); sons >aisplay0: son) Heavymotorvehlele(Tata ‘Truck’ 1220000,25) Sobt-raisplay0 sobs=new Heavymotorvehicl("Baja:200000.25); sobs display SobB-new Heavymotorvehiclemahindat 900000.2 5: Sob6->display0s rsdn snd ert fGstheeed wersaage ‘comm ene FOUR HRD, rate so resto 7 Pe bet rncion re: lass ean extends Shape t fancon coro. 59) C c c i , clas adr etn Shape ‘anon sonarus 9) i Shey ’ : , lace extent Shape fi on , Cc uncon vtumed) "sun FOUR TRDS Po y , se + etn area, 0 Se Ae Menge opine ane spe Rectang snag SsbA 8 seem mecagit 4 seh eRe ane sug, HP ee "Se 2Define a class Employee having vatemembers =i, name lepartment, sala Deine Pakameterized constructors Create Fithelass called “Stamager” with private member bonus, Create 6 objectsot the Manager clase and display the details of the manager having the maximumtotal Salary ealary bonus) eid=$a; Sthis>ename=Sb; Sthis>edept$e; sthis>salesdi ) public function getdatad ‘ return Sthis->sals 1 public function display { echo sthis-eid"°; ‘echo Sthis->ename.” ‘echo Sthis>edept."*; ) ) ‘lass Manager extends Employee ‘ private Sbonus; public static Stotalt-0; function _construct(8a,sb,86,8,$e) ‘ parents_construct(fa.sb.se.sd); ‘this >bonus-Se; ) public function max(sob) { Ss his getdatad; ‘Stotal-Seal-Sthis->bonus; intstotal>set:stotatl) { selfftotalt-stotal; return Sthis; ) else { return Sb; ) ) public function display 1 parencidisplayo; fecha self:stotalt; } ? Sob-new Manager(0,"ABC".0.0) Sob1-new Manager(1,Archana’,"HR"28000,2000); ‘Sob-Sab1->maxt Sob); Sob2-new Manager(2,Adhira’"Tester”30000,2500); ‘Sob-S0b2->maxt Sob); sob3-new Manager(3,Amol"PM",32000,8000); ‘Sob-S0b3>maxt Sob); Sob-display0; 2 Derhe aceee sare. tee cee Rectangle create one more cass crete, ESSIES, inners "wth any ans fret ened aren 0. Implements IRCA he ces noe cikschctors in''all cassestWeite a Eee octangle ana display the ‘ptm smb ody? “or con~ap Sp mathodyt> sh Square : Enter se for Square: oe ae "; ) , elas ciele ‘ funetion areatsr sr) ‘ Saree = 05°Se°5 cho “Area of Cite", Serene ) ) Si = new rectangles StrareasL8by Sis = new square Stsmareatss) Ste = new cece Steoareatse.s0) 2Define a class Employee having vatemembers =i, name lepartment, sala Deine Pakameterized constructors Create Fithelass called “Stamager” with private member bonus, Create 6 objectsot the Manager clase and display the details of the manager having the maximumtotal Salary ealary bonus) eid=$a; Sthis>ename=Sb; Sthis>edept$e; sthis>salesdi ) public function getdatad ‘ return Sthis->sals 1 public function display { echo sthis-eid"°; ‘echo Sthis->ename.” ‘echo Sthis>edept."*; ) ) ‘lass Manager extends Employee ‘ private Sbonus; public static Stotalt-0; function _construct(8a,sb,86,8,$e) ‘ parents_construct(fa.sb.se.sd); ‘this >bonus-Se; ) public function max(sob) { Ss his getdatad; ‘Stotal-Seal-Sthis->bonus; intstotal>set:stotatl) { selfftotalt-stotal; return Sthis; ) else { return Sb; ) ) public function display 1 parencidisplayo; fecha self:stotalt; } ? Sob-new Manager(0,"ABC".0.0) Sob1-new Manager(1,Archana’,"HR"28000,2000); ‘Sob-Sab1->maxt Sob); Sob2-new Manager(2,Adhira’"Tester”30000,2500); ‘Sob-S0b2->maxt Sob); sob3-new Manager(3,Amol"PM",32000,8000); ‘Sob-S0b3>maxt Sob); Sob-display0; ‘Write a PHP script to demonstrate the introspection for examining class(use function get_declared_classes() ,get_class_methods() and get_class_vars()). intro.php-Method 1 "; echo"
Class Methods are :
"; $m=get_class_methods('Myclass'); foreach($m as $mname) { echo"$mnamesbr>"; } Scp=get_class_vars('Myclass’); echo" class variables are :
"; foreach($cp as $cpname => $v) { echo"$cpname : $v
"; Define an Interface which has method gmtokg() &kgtogm(). Create Class Convert which implements this interface & convert the value kg to gm and gm to kg. w=$w; } function gmtokg0 if echo"Value in gram :".$this>w."
w=$this->w/1000; echo"Value in kg= ".$this- >w." Kilogram
"; ui function kgtogm0 f echo"value in kilogram:".sthis->w."
"; Sthis->w=$this->w*1000; echo"value in gm= echo"value in kilogram:".$this->w."
"; Sthis->w=$this->w*1000; echo"value in gm= "$this>w." Gram
"; } $c=new Convert(1000); $c->gmtokg(); $c=new Convert(4); $c->kgtogm0; ied

You might also like