- Abstract Method:
- Abstract methods are declared within an abstract class but have no implementation (i.e., no method body). This requires any subclass inheriting from the abstract class to provide a concrete implementation of the abstract method, unless the subclass is also abstract.
- Abstract methods define a template that derived classes must adhere to, ensuring all derived classes share the same behavioral interface.
- Virtual Method:
- Virtual methods are declared in a class using the
virtualkeyword and provide a basic implementation that can be overridden by any subclass inheriting from it. - Virtual methods enable subclasses to modify or extend the behavior of the parent class's methods without altering the interface specification.
In summary, abstract methods enforce derived classes to implement specific methods, while virtual methods provide a base implementation that derived classes can freely override.