fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Vehicle {
  5. public:
  6. void SetSpeed(int speedToSet) {
  7. speed = speedToSet;
  8. }
  9.  
  10. void PrintSpeed() {
  11. cout << speed;
  12. }
  13.  
  14. private:
  15. int speed;
  16. };
  17.  
  18. class Car : public Vehicle {
  19. public:
  20. void PrintCarSpeed() {
  21. cout << "Driving at: ";
  22. PrintSpeed();
  23. }
  24. };
  25.  
  26. int main() {
  27. Car myCar;
  28. myCar.SetSpeed(30);
  29.  
  30. myCar.PrintCarSpeed();
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Driving at: 30