The four fundamental principles of object-oriented programming in Java: encapsulation, inheritance, polymorphism, and abstraction. Each addresses a distinct concern in software design, but together they form a cohesive paradigm.
The four pillars balance competing goals: encapsulation hides state (safety), inheritance shares code (reuse), polymorphism enables flexibility (adaptability), and abstraction reduces complexity (clarity). Over-emphasizing any one pillar leads to design problems — rigid hierarchies from overusing inheritance, or anemic models from over-encapsulation.
| Dimension | Encapsulation | Inheritance | Polymorphism | Abstraction |
|---|---|---|---|---|
| Purpose | Data hiding | Code reuse | Runtime flexibility | Complexity reduction |
| Mechanism | Access modifiers, getters/setters | extends, super | Method overriding, overloading | Abstract classes, interfaces |
| Java keyword | private, protected | extends | @Override, overloaded names | abstract, interface |
| Anti-pattern | Anemic domain model | Deep hierarchy, fragile base class | Type-checking with instanceof | Leaky abstraction |
The four pillars are not independent — they reinforce each other. Encapsulation protects the internal state that inheritance extends. Polymorphism enables the runtime dispatch that abstraction promises. A well-designed Java class system uses all four in concert: encapsulation hides data, inheritance shares behavior, abstraction defines contracts, and polymorphism enables substitution.
- Java Encapsulation — data hiding and access control
- Java Inheritance — code reuse and hierarchy
- Java Polymorphism — dynamic dispatch and flexibility
- Java Abstraction — complexity management
- Java Interfaces — abstraction through contracts
- Access Modifiers — the mechanism for encapsulation