Abstract classes and Interfaces are today’s items of discussion.
Sealed modifier prevents other classes from inheriting from it.
Please see following example how to use it.
In C#, the abstract modifier is used to define an abstract class. Abstract class cannot be instantiated, and is frequently either partially implemented, or not at all implemented.
One key difference between abstract classes and interfaces is that a class may implement an unlimited number of interfaces, but may inherit from only one abstract (or any other kind of) class.
An example of abstract class:
Some inherited class from out abstract class. Sure, derived class can be instantiated. Pay your attention this class is sealed.
An interface is not a class. An interface is defined as a syntactical contract that all the classes inheriting the interface should follow. An interface contains only the signatures of methods, properties, events or indexers. We’ll talk later about events and indexers. A class or struct that implements the interface must implement the members of the interface that are specified in the interface definition.
Simple interface to have been defined with one property and method.
- Abstract classes 1
- Abstract classes 2
- Interfaces 2
- Abstract Class versus Interface
- Download Source Code