search

Home  >  Q&A  >  body text

This is a big php programming question. I have no choice. Please help.

Define a parent class Person (person), including two attribute members xm (name), xb (gender) and a constructor. xm and xb cannot be read and written directly in the main program. Name, xb are completed in the constructor. Initialization of gender.

Define a subclass teacher (teacher) inherited from Person, including the attribute gh (employee number) and a constructor. You cannot directly read and write gh in the main program. The constructor can be used to initialize all data members. And define a method in the subclass to output all teacher information, and define a destructor to display "Goodbye".

There is currently a teacher "李思", gender "male", and job number 123. Please initialize it with this data and output


有为鱼有为鱼2154 days ago1104

reply all(3)I'll reply

  • Miss等待

    Miss等待2019-01-10 16:00:49

    <?php


    class Person

    {

    protected $xm;

    protected $xb ;


    function __construct()

    {

    $this->xm = '李思';

    $this->xb = 'Male';

    }


    ##}


    ## class Teacher extends Person

    {

    protected $gh;

    ## function __construct()

    {

    $this->gh = 123;

    $this->xm = '李思';

    $this->xb = 'Male';

    }

    public function message()

    {

    return "The name is: {$this->xm} Gender is: {$this->xb} Job number is: {$this->gh}";

    }

    function __destruct( )

    {

    // return 'Goodbye!';

    echo 'Goodbye! ';

    }

    }

    ##$teacher = new Teacher();


    echo $teacher->message();

    reply
    0
  • 空城

    空城2019-01-09 14:06:26

    You posted it, I was stunned by what you said

    reply
    0
  • 有为鱼

    I also want someone to give me the answer. If not, I wouldn’t have posted this post.

    有为鱼 · 2019-01-09 15:01:44
  • Cancelreply