-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabstract.cpp
More file actions
35 lines (29 loc) Β· 1000 Bytes
/
abstract.cpp
File metadata and controls
35 lines (29 loc) Β· 1000 Bytes
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
#include <iostream>
using namespace std;
// Abstract class with a pure virtual function (abstract method)
class Vehicle {
public:
// Pure virtual function (abstract method)
virtual void startEngine() = 0; // No implementation, must be overridden by derived class
// Regular method to show common behavior
void fuelUp() {
cout << "β½ Fueling up the vehicle!" << endl;
}
};
// Derived class that provides implementation for the abstract method
class Car : public Vehicle {
public:
// Overriding the pure virtual function (abstract method)
void startEngine() override {
cout << "π Starting the car's engine... Vroom Vroom!" << endl;
}
};
// Main function
int main() {
// Creating an object of the derived class (Car)
Car myCar;
// Calling the implemented methods
myCar.startEngine(); // Output: π Starting the car's engine... Vroom Vroom!
myCar.fuelUp(); // Output: β½ Fueling up the vehicle!
return 0;
}