1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include <iostream>
- using namespace std;
- class Vehicle {
- public:
- void Run() {
- cout << "Vehicle is running" << endl;
- }
- void Stop() {
- cout << "Vehicle stops" << endl;
- }
- };
- class Bicycle : public Vehicle {
- public:
- void Run() {
- cout << "Bicycle is running" << endl;
- }
- void Stop() {
- cout << "Bicycle stops" << endl;
- }
- };
- class Motorcar : public Vehicle {
- public:
- void Run() {
- cout << "Motorcar is running" << endl;
- }
- void Stop() {
- cout << "Motorcar stops" << endl;
- }
- };
- class Motorcycle : public Bicycle, public Motorcar {
- public:
- void Run() {
- cout << "Motorcycle is running" << endl;
- }
- void Stop() {
- cout << "Motorcycle stops" << endl;
- }
- };
- int main() {
- Vehicle v;
- v.Run();
- v.Stop();
- Bicycle b;
- b.Run();
- b.Stop();
- Motorcar m;
- m.Run();
- m.Stop();
- Motorcycle mc;
- mc.Run();
- mc.Stop();
- Vehicle* vp = &v;
- vp->Run();
- vp->Stop();
- vp = &b;
- vp->Run();
- vp->Stop();
- vp = &m;
- vp->Run();
- vp->Stop();
- vp = &mc;
- vp->Run();
- vp->Stop();
- return 0;
- }
|