php 类继承--单继承

php 类继承--单继承
<?php
    class BaseClass{
        function __construct(){
            echo "<br><font color=red>this is the base class constructor</font><br>";
        }
    }
    class SubClass extends BaseClass{
        function __construct(){
#子类调用父类构造方法的两种,父类名::__construct();parent::__construct()
            BaseClass::__construct();
            parent::__construct();
            echo" <br> this is the sub class constructor<br>";
        }
    }
    echo "declare an instance of BaseClass<br>";
    $obj=new BaseClass();

    echo "declare an instance of SubClass<br>";
    $obj1=new SubClass();
?>

你可能感兴趣的:(php 类继承--单继承)