- Programming Methodologies
- Types of Classes in C#
- Polymorphism in C#
- Types of Inheritance in C#
- Method Overloading and Method overriding C#
- Sealed Class in C#
- Encapsulation in C#
- Interfaces are declared using the interface keyword.
- Default access modifiers for interface are internal.
- Members of interfaces cannot be private.
- We cannot be applied any access modifier to the interface members because by default they are public.
- A class can implement several interfaces.
- Interfaces must be implemented using classes.
- An Interface does not have a constructor.
- All methods inside the interfaces must be implemented.
- Interfaces cannot contain a body of any of its methods.
|Classes have any access modifier.||It cannot be allowed to be declared as private.|
|We can create instances of classes.||Cannot create an instance of an interface.|
|Class members have any access modifiers.||Cannot apply any access modifier to members because by default they are public.|
|Class methods have an implementation.||Interface methods have no implementation.|
|A class contains any type of method.||Interface has only abstract methods.|
|Cannot inherit multiple classes.||Multiple Interfaces are inherited.|
|Classes may inherit only one abstract class.||Class may inherit multiple interfaces.|
|Abstract Class members have access modifiers.||Interface members are by default public.|
|Abstract Class methods have implementation or no implementation.||Interface methods have no implementation.|
|An Abstract Class contains abstract as well as non-abstract methods.||Interface has only abstract methods.|
|When you want an implementation or no implementation of methods then use an abstract class.||If you do not want any implementation of methods then use interfaces.|
I hope this article is useful for all students and beginners. If you have any suggestion related to this article then please contact me.