Blogger Information
Blog 26
fans 0
comment 0
visits 15649
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
接口和抽象类
庄周梦蝶
Original
622 people have browsed it
  1. <?php// 接口
  2. interface iDbd
  3. {
  4. const JS = '计算加减乘除';
  5. public static function m1($a, $b);
  6. public static function m2($a, $b);
  7. public static function m3($a, $b);
  8. public static function m4($a, $b);
  9. }
  10. class DD_Db implements iDbd
  11. {
  12. public static function m1($a, $b)
  13. {
  14. return "$a + $b =".($a+$b);
  15. }
  16. public static function m2($a, $b)
  17. {
  18. return "$a - $b =".($a - $b);
  19. }
  20. public static function m3($a, $b)
  21. {
  22. return "$a X $b =".($a * $b);
  23. }
  24. public static function m4($a, $b)
  25. {
  26. return "$a / $b =".($a / $b);
  27. }
  28. }
  29. echo iDbd::JS, '<br>';
  30. echo DD_Db::m1(1,2),'<br>';
  31. echo DD_Db::m2(3,2),'<br>';
  32. echo DD_Db::m3(2,2),'<br>';
  33. echo DD_Db::m4(10,2),'<br>';
  34. // 抽象类
  35. abstract class Abc
  36. {
  37. public static function m1($a)
  38. {
  39. return $a;
  40. }
  41. abstract public function __construct();
  42. }
  43. class Aac extends Abc
  44. {
  45. public function __construct(...$b)
  46. {
  47. echo print_r($b,true),'<br>';
  48. }
  49. }
  50. new Aac('aa','cc','dd');
  51. echo Aac::m1(5);
  52. //在抽象类中可以写公共不抽象方法,但是在接口中不能写不抽象类方法,
  53. ![](https://img.php.cn/upload/image/583/156/446/1618395069697127.png)
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post