Week 5 Blog Post

#1
  1. What is an interface?

Like a class, Interface can have methods, properties, events, and indexers as its members. But interfaces will contain only the declaration of the members. The implementation of interface’s members will be given by class who implements the interface implicitly or explicitly.

  • Interfaces specify what a class must do and not how.
  • Interfaces can’t have private members.
  • By default all the members of Interface are public and abstract.
  • The interface will always defined with the help of keyword ‘ interface ‘.
  • Interface cannot contain fields because they represent a particular implementation of data.
  • Multiple inheritance is possible with the help of Interfaces but not with classes.
  1. What is an abstract class?

The abstract modifier indicates that the thing being modified has a missing or incomplete implementation. The abstract modifier can be used with classes, methods, properties, indexers, and events. Use the abstract modifier in a class declaration to indicate that a class is intended only to be a base class of other classes, not instantiated on its own. Members marked as abstract must be implemented by classes that derive from the abstract class.

  1. How are abstract classes and interfaces different?

An abstract class is a way to achieve the abstraction in C#. An Abstract class is never intended to be instantiated directly. This class must contain at least one abstract method, which is marked by the keyword or modifier abstract in the class definition. The Abstract classes are typically used to define a base class in the class hierarchy.

Like a class, Interface can have methods, properties, events, and indexers as its members. But interfaces will contain only the declaration of the members. The implementation of interface’s members will be given by the class who implements the interface implicitly or explicitly.


https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/abstract