Concept Flow - OOP principles overview
Start
Encapsulation
Inheritance
Polymorphism
Abstraction
End
This flow shows the four main OOP principles in order: Encapsulation, Inheritance, Polymorphism, and Abstraction.
#include <iostream> class Animal { public: virtual void sound() { } }; class Dog : public Animal { public: void sound() override { std::cout << "Woof"; } };
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Create Animal object | Animal a; | Object a created |
| 2 | Call a.sound() | a.sound(); | No output (empty method) |
| 3 | Create Dog object | Dog d; | Object d created |
| 4 | Call d.sound() | d.sound(); | Outputs: Woof |
| 5 | Assign Dog to Animal pointer | Animal* ptr = &d; | Pointer ptr points to Dog object |
| 6 | Call ptr->sound() | ptr->sound(); | Outputs: Woof (polymorphism) |
| 7 | End | Execution stops |
| Variable | Start | After Step 1 | After Step 3 | After Step 5 | Final |
|---|---|---|---|---|---|
| a | none | Animal object | Animal object | Animal object | Animal object |
| d | none | none | Dog object | Dog object | Dog object |
| ptr | none | none | none | Points to Dog object | Points to Dog object |
OOP Principles Overview in C++: - Encapsulation: Bundle data and methods in classes - Inheritance: Derive new classes from existing ones - Polymorphism: Use virtual functions to override behavior - Abstraction: Hide complex details behind simple interfaces Use virtual keyword for polymorphism.