fork download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. class Car{
  6. protected $speed;
  7. public function setSpeed($speed){
  8. $this->speed = speed;
  9. }
  10. public function getSpeed(){
  11. return $this->speed;
  12. }
  13. }
  14.  
  15. class Truck extends Car{
  16. public function setSpeed($level){
  17. switch($level){
  18. case 1:
  19. $this->speed = 60;
  20. break;
  21. case 2:
  22. $this->speed = 100;
  23. break;
  24. case 3:
  25. $this->speed = 120;
  26. break;
  27. default:
  28. $this->speed = 80;
  29. break;
  30. }
  31. }
  32. }
  33.  
  34. $truck = new Truck;
  35.  
  36. $truck->setSpeed(1);
  37. echo $truck->getSpeed();
  38.  
  39. $truck->setSpeed(3);
  40. echo $truck->getSpeed();
  41.  
  42. ?>
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
60120