Oops / Abstraction / Difference between Abstract class and Interface
Abstract class vs Interfaces
-
Note
1. What
Interface and Abstract class are used to achieve the oops feature polymorphism and abstraction.
2. Difference
Features Abstract class Interface Purpose Provides a base class with shared logic Defines a contract (what must be implemented) Methods Can have abstract (no body) and concrete (with body) methods Only method signatures (no body) Properties Can define properties (variables) Cannot have regular properties Inheritance Single inheritance only A class can implement multiple interfaces Use Case when you need to share code across related classes with comman structure when you want to enforce comman structure across unrelated classes Access Modifiers Can use public, protected, or private Methods are always public Constructor Can have constructors Cannot have constructors
MANVIA BLOG