"Explain the four pillars of Object-Oriented Programming (OOP) with examples."
Sigiloso
The four pillars of OOP are: - Encapsulation: Wrapping data and methods into a single unit (class). Example: A BankAccount class with private balance and public methods like deposit() and withdraw(). - Inheritance: Acquiring properties and behaviors from another class. Example: A SavingsAccount class inheriting from BankAccount. - Polymorphism: Ability to take many forms—methods behave differently based on context. Example: Method calculateInterest() behaves differently in SavingsAccount vs FixedDepositAccount. - Abstraction: Hiding complex implementation and showing only essential features.