OOP_in_Cpp
OOP_in_Cpp
What is OOP?
code reuse.
(method overloading).
OOP in C++
C++ is a popular language that supports Object-Oriented Programming. Below
- Example:
class Car {
public:
string brand;
int speed;
void drive() {
};
- Creating an object:
Car myCar;
myCar.brand = "Toyota";
myCar.speed = 120;
myCar.drive();
2. Encapsulation:
- Example:
class Account {
private:
double balance;
public:
balance = amount;
double getBalance() {
return balance;
};
3. Inheritance:
- Example:
class Vehicle {
public:
void start() {
};
public:
void drive() {
};
4. Polymorphism:
- Method Overriding:
class Animal {
public:
};
public:
};
5. Abstraction:
- Example:
class Shape {
public:
};
public:
}
};