In data abstraction, non-essential facts are concealed and only necessary ones are displayed to the user

Both abstract classes and interfaces are capable of achieving abstraction.

 

Abstraction By Abstract Class

  • All methods and classes use the abstract keyword:
  • An abstract class cannot be directly used to produce objects; instead, it can only be accessed via inheriting it from another class.
  • Abstract method does not have a body and can only be used in abstract classes. Inheriting from a derived class provides the body.

 

 

 

Abstraction Interface

Interfaces are another tool at C# abstraction. An interface is a completely “abstract class” that may only have abstract properties and methods:


An interface can only be accessed by classes that have "implemented" (or "inherited") it. Similar to inheritance, the : symbol is used to implement an interface. In the "implement" class, you'll find the actual interface method body.


Related Question