18 Jul 2021

OOP code PHP

 <?php

class Hemanth

{

    const b=20;

    public $name;

    const amt=20;

    function hero($name)

    {

        $this->name=$name;

    }

    function _construct($name)

    {

        $this->name=$name;

    }

    function hero1()

    {

        return $this->name;

    }

    function _destruct()

    {

        echo $this->name;

    }

}


class Sreekanth extends Hemanth

{

    public function hem()

    {

        echo "Hi How are You";

    }

}

trait Room  //To access Multiple Inheritance

{

    public function room()

    {

        echo "Hemanth Kumar Tanguturi";

    }

}

class Temple

{

    use Room;

}

class King

{

    public static $value=3.141419;

    

    public static function king1()

    {

        echo "Hemanth is a  Hero";

        return self::$value;

    }

}

class Mankind

{

    public $great;

    public $cool;

    public function human()

    {

        echo $this->great;

        echo $this->cool;

    }

}

class Queen

{

    public function dualrole()

    {

        $arr=["a","b","c","d"];

        foreach($arr as $x)

        {

            echo $x;

        }

    }

}

$a=new Hemanth();

$a->hero('Hemanth');

echo $a->hero1();

echo Hemanth::b;

$c=new Sreekanth();

$c->hem();

King::king1();

$e=new King();

$e->king1();

$f=new Mankind();

$f->great=1000;

$f->cool="Hemanth";

$f->human();

$g=new Queen();

$g->dualrole();

No comments:

Post a Comment