Real life example
ATM machine: aap sirf buttons dabate ho. Andar cash ginne ki machine nahi dekhte.
Industry example
Payment gateway (JazzCash, Easypaisa) apna logic chupa kar sirf pay() button deta hai.
C++ code
class Atm {
int cash = 100000; // private
public:
bool withdraw(int x){
if(x <= cash){ cash -= x; return true; }
return false;
}
};
What happens when it runs
withdraw(5000) = true atm.cash (bahar se) = Error: private
Run the full program in the compiler Interactive version
Quiz
Interface kya hota hai?
Interface bahar ka darwaza hai. Implementation andar chupi rehti hai.
Try it yourself
Write one example of Encapsulation aur Interface from your own home, school or work. Then change the program in the compiler and run it again.
All 12 OOP lectures
- Lecture 1: Introduction aur Objects
- Lecture 2: Encapsulation aur Interface
- Lecture 3: Abstraction, Class, Inheritance
- Lecture 4: Inheritance ke Concepts
- Lecture 5: Association, Composition, Aggregation
- Lecture 6: Polymorphism
- Lecture 7: C++ me Class
- Lecture 8: Constructor
- Lecture 9: Copy Constructor, Destructor, this
- Lecture 10: this Pointer aur const Functions
- Lecture 11: const, Initializer List, static
- Lecture 12: static Functions aur Array of Objects
START WELL TO END WELL