1/9
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
What are the 4 principles of OOP?
Encapsulation
Abstraction
Inheritance
Polymorphism
What is Encapsulation?
Encapsulation is bundling data (properties) and methods that operate on that data into a single unit (class) and restricting direct access to some of the object’s components.
Why is Encapsulation important?
Protects data
Prevents unintended modification
Improves maintainability
Controls access using public/private/protected
What is Abstraction?
Abstraction is hiding complex implementation details and exposing only the essential features of an object.
How is Abstraction achieved?
Interfaces
Abstract classes
Public APIs
What is Inheritance?
Inheritance allows a class (child) to acquire properties and methods of another class (parent).
Why use Inheritance?
Code reuse
Logical hierarchy
Easier maintenance
Extending existing behavior
What is Polymorphism?
Polymorphism means “many forms” — the same method can behave differently depending on the object that calls it.
Types of Polymorphism
Method overriding (runtime)
Method overloading (compile-time, in some languages)
Real-world example of Polymorphism
A draw() method:
Circle → draws a circle
Square → draws a square