abstract:<?php class Car{ public static $speed = 120; public static $fuel = 100; public&n
<?php class Car{ public static $speed = 120; public static $fuel = 100; public static $color ='红色'; public static $brand = '五菱宏光'; public static function move() { return ' 正在以'.static::$speed .'的速度行驶,油量为:'. static::$fuel; } public static function state() { return '有辆牌子为'.static::$brand.static ::move(); } } class Supercar extends Car { public static $speed = 240; public static $fuel = 200; public static $brand = '五菱宏光S'; public static function move() { return '颜色为'.static::$color. ' 正在以'.static::$speed .'的速度行驶,油量为:'. static::$fuel; } } $car = new Car; echo $car::state().'<hr>'; $supercar = new Supercar; // echo $supercar::move().'<hr>'; echo $supercar::state().'<hr>'; echo $car::state().'<hr>'; ?>
经过本章节的学习,对后期静态绑定重载技术比较深入的了解,在子类静态成员中如果不重新赋值即继承了父类的静态成员的值,当对父类的静态成员进行覆写即是更新了继承的成员值进行改变。从而达到代码的复用性和让子类的功能更加灵活、多元化。
Correcting teacher:天蓬老师Correction time:2019-04-11 09:03:09
Teacher's summary:这些知识, 有点抽象 , 要多想,想好了再写, 效果会更好