php中静态方法如何继承
导读
PHP中静态方法继承的方法:
之前一直对子类能否对静态函数进行override,故写了段测试代码,代码如下:
<?php Class A { var $a='I/'m A'; function write() { echo 'I can be overriden!<br />'; } static function no_write() { echo 'Can I be overriden?<br />'; } } Class B extends A { function write() { echo 'Override from A successfully!<br />'; } static function no_write() { echo 'Can I override successful?<br />'; } } $a=new A; $a->write(); $a->no_write(); $b=new B; echo $b->a.'<br />'; //Attributes can be inherited $b->write(); $b->no_write(); //static methods can be overriden ?>
运行结果如下:
I can be overriden! Can I be overriden? I'm A Override from A successfully! Can I override successful?
所以说,静态函数在子类里是可以被override的,但是在java里就不太清楚了,准备自己再写些代码测试下。
评论(0)