0% found this document useful (0 votes)
12 views16 pages

PHP Prac 8

Uploaded by

saeedarwatkar
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)
12 views16 pages

PHP Prac 8

Uploaded by

saeedarwatkar
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

P

Practical No. 8
1) Write a program to implement a Constructor.
<?php

class A

function __construct()

echo "From Constructor";

$obj=new A();

?>

Output:
2) Write a program to implement Destructor.
<?php

class A

function __construct()

echo "From Constructor <br>";

function __destruct()

echo "Destructor Called";

$obj=new A();

?>

Output:
3) WAP to implement Single Inheritance.
<?php

class A

public function display1()

echo "From Parent class A <br>";

class B extends A

public function display2()

echo "From Child class B";

$obj=new B();

$obj->display1();

$obj->display2();

?>

Output:
4) WAP to implement Multilevel Inheritance.
<?php

class A

public function display1()

echo "From Parent class A<br>";

class B extends A

public function display2()

echo "From Intermediate class B<br>";

class C extends B

public function display3()

echo "From Child class C";

$obj=new C();

$obj->display1();
$obj->display2();

$obj->display3();

?>

Output
5) WAP to implement Hierarchical Inheritance.
<?php

class A

public function display1()

echo "From Parent Class A <br>";

class B extends A

public function display2()

echo "From Child class B<br>";

class C extends A

public function display3()

echo "From Child Class C";

$obj1=new B();

$obj2=new C();
$obj1->display1();

$obj1->display2();

$obj2->display3();

?>

Output:
6) WAP to implement Multiple Inheritance through traits.
<?php

class A

public function display1()

echo "From Parent class A<br>";

trait B

public function display2()

echo "From Trait B<br>";

class C extends A

use B;

public function display3()

echo "From Child class C";

$obj=new C();
$obj->display1();

$obj->display2();

$obj->display3();

?>

Output:
7) WAP to implement Multiple Inheritance through Interface.
<?php

class A

public function display1()

echo "From Parent class A<br>";

interface B

public function display2();

class C extends A implements B

public function display2()

echo "From Interface B<br>";

public function display3()

echo "From child class C";

$obj=new C();
$obj->display1();

$obj->display2();

$obj->display3();

?>

Output:
8) WAP to implement Method Overriding.
<?php

class A

public function display()

echo "From Parent Class...<br>";

class B extends A

public function display()

echo "From Child Class...";

$obj=new B();

$obj->display();

?>

Output:
9) WAP to implement Method Overloading through __call() method.
<?php

class Demo

public function __call($name,$args)

if($name=="show")

switch(count($args))

case 1:

return "Method with 1 argument: ".$args[0];

break;

case 2:

return "Method with 2 arguments: ".$args[0]." ".$args[1];

break;

case 3:

return "Method with 3 arguments: ".$args[0]." ".$args[1]." ".$args[2];

break;

$obj=new Demo();

echo $obj->show("Hii");

echo "<br>";
echo $obj->show("Hii","Saee");

echo "<br>";

echo $obj->show("Hii",
>show("Hii", "Saee", "Darwatkar");

?>

Output:
10) WAP to implement multiple inheritance through __callStatic() method .
<?php

class Demo

static public function __callStatic($name,$args)

if($name=="show")

switch(count($args))

case 1:

return "Method with 1 argument: ".$args[0];

break;

case 2:

return "Method with 2 arguments: ".$args[0]." ".$args[1];

break;

case 3:

return "Method with 3 arguments: ".$args[0]." ".$args[1]." ".$args[2];

break;

echo Demo::show("10");

echo "<br>";
echo Demo:: show("20","30");

echo "<br>";

echo Demo::show("40", "50", "60");

?>

Output:

You might also like