class father
{        //定义father类
    public function getMethod()
    {        //定义方法
        $this->method();
    }

    public function method()
    {        //定义方法
        echo '<br />father method';
    }
}

class son extends father
{        //定义继承自father类的son类
    public function method()
    {        //重写父类方法        
        echo 'son method';
    }
}

$son = new son();        //实例化son类的对象
//调用son类的方法
$son->getMethod();

输出:son method

相关文章:

  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-02
  • 2022-12-23
  • 2021-05-03
猜你喜欢
  • 2022-03-11
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案