Creating an abstract `PaymentProcessor` interface implemented by `StripeProcessor` and `PayPalProcessor` using Polymorphism.
abstract class PaymentProcessor {
abstract processPayment(amount: number): boolean;
}
class StripeProcessor extends PaymentProcessor {
processPayment(amount: number): boolean {
console.log("Processing Stripe payment: $" + amount);
return true;
}
}Visual representation of control loops, memory layout, and execution flow for The 4 Pillars of OOP.
Bundle fields and methods together, declaring fields private and exposing public getters/setters.
Expose high-level interfaces while hiding low-level implementation details.
Derive child classes from parent base classes to reuse attributes and behavior.
Override methods in child classes so calling a base method executes specific child logic.
| Feature / Dimension | Abstract Class | Interface |
|---|---|---|
| Method Implementation | Can contain both abstract and implemented concrete methods | Only defines method signatures (in standard OOP) |
| Multiple Inheritance | Class can inherit from only 1 Abstract Class | Class can implement MULTIPLE Interfaces |
| Fields | Can have instance fields with state | Only constants (public static final) |
Detailed answers, interviewer pro tips, key takeaway summaries, and code examples formulated for technical rounds.
✅ Correction: Design Principle: "Favor Composition over Inheritance" to avoid rigid class hierarchies.
Core architectural principles for object-oriented design.