---
title: "Abstraction"  
description: "Abstraction is used to create a common set of methods that might have different specific implementations by subclasses. Abstract class cannot be insta"  
author: "Anonymous User"  
published: 2012-09-11  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/361/abstraction  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# Abstraction

[Abstraction](https://www.mindstick.com/articles/944/abstraction-in-c-sharp) is used to create a common set of methods that might have different specific implementations by subclasses. [Abstract class](https://www.mindstick.com/articles/1430/abstract-class) cannot be instantiated and consists of [abstract methods](https://www.mindstick.com/forum/159550/how-to-implement-an-interface-with-two-abstract-methods-by-a-lambda-expression) without any implementations. Classes inheriting from abstract class must implement all the methods in abstract class. An abstract class is a parent class that allows [inheritance](https://www.mindstick.com/articles/13095/inheritance-and-its-types) but can never be instantiated. [Abstract classes](https://www.mindstick.com/forum/158818/what-are-abstract-classes-in-oop-and-when-are-they-used) contain one or more abstract methods that do not have [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp).

Example:-

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Abstraction{publicabstract classTalk //Abstract Class{// An abstract method is a method without any method body.public abstract void Speak();// Abstract Method( only declaration with empty body)}publicclass sayMorning : Talk // Inheriting the Abstract Class{public override void Speak() // Overrinding the Abstract Method (Defining the base class Abstract Method){Console.WriteLine("Good Morning"+ "\n");}}publicclass sayAfterNoon : Talk{public override void Speak(){Console.WriteLine("Good Afternoon" + "\n");}}publicclass sayNight : Talk{public override void Speak(){Console.WriteLine("Good Night" + "\n");}}classProgram{static void Main(string[] args) //The main entry point for the application.{// Talk objTalk = new Talk(); // It will Generate and error because Abstract Class can'b be instantiatedsayMorning objSayMorning = new sayMorning(); //Creating ObjectsayAfterNoon objSayAfternoon = new sayAfterNoon();sayNight objSayNight = newsayNight();objSayMorning.Speak(); objSayAfternoon.Speak();objSayNight.Speak();}}}
```

##### Output:-

## Good Morning

## Good Afternoon

## Good Night

In the above Program, I have created an Abstract [Base Class](https://www.mindstick.com/blog/116/base-class-initilization) named Talk, Which contain an [Abstract Method](https://www.mindstick.com/articles/23305/abstract-methods-and-class-in-c-sharp) Speak () with declaration only (abstract methods are further defined in [Sub Class](https://answers.mindstick.com/qa/92538/what-are-the-base-class-sub-class-and-superclass) of Abstract Base Class and must be overridden by Sub Class).

This Program also contains three more classes named sayMorning, sayAfterNoon, sayNight. All these three classes are inheriting the Abstract Base Class names Talk and overriding the abstract method using override keyword (Implementation logic of Abstract Methods are provided by class that derive from them).

---

Original Source: https://www.mindstick.com/blog/361/abstraction

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
