-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhybrid.cpp
44 lines (39 loc) · 1.01 KB
/
hybrid.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//code by vishwa
#include <iostream>
using namespace std;
// Base class
class Vehicle {
public:
void start() {
cout << "Vehicle started" << endl;
}
};
// Intermediate class (inherits from Vehicle)
class Car : public Vehicle {
public:
void drive() {
cout << "Car is driving" << endl;
}
};
// Intermediate class (inherits from Vehicle)
class Boat : public Vehicle {
public:
void sail() {
cout << "Boat is sailing" << endl;
}
};
// Derived class (inherits from Car and Boat)
class AmphibiousVehicle : public Car, public Boat {
public:
void moveOnLandAndWater() {
cout << "Amphibious vehicle can move on land and water" << endl;
}
};
int main() {
AmphibiousVehicle av;
av.Car::start(); // Ambiguity resolved by specifying the base class
av.drive(); // From Car class
av.sail(); // From Boat class
av.moveOnLandAndWater(); // Own method of AmphibiousVehicle class
return 0;
}