A class is a blueprint for creating objects, which are instances of classes.
class Car {
public:
string model;
void drive() {
cout << "Driving " << model;
}
};
Inheritance allows a class to acquire properties of another.
class Animal {
public:
void speak() { cout << "Animal"; }
};
class Dog : public Animal {
// Inherits speak()
};
Polymorphism allows the same interface to have different implementations. It comes in two forms:
Encapsulation hides the internal details and exposes only necessary parts via access specifiers (private
, public
, protected
).