---
title: "Abstraction in oops c#"  
description: "Abstraction is a general concept which you can find in the real world as well as in OOPS Concept. Any objects in the real world."  
author: "Rashmi Sharma"  
published: 2021-05-14  
canonical: https://www.mindstick.com/articles/326534/abstraction-in-oops-c-sharp  
category: "c#"  
tags: ["c#", "abstract class", "abstraction"]  
reading_time: 2 minutes  

---

# Abstraction in oops c#

**[Abstraction](https://www.mindstick.com/blog/668/abstraction-and-encapsulation) :-**

It Displays only necessary details and hides unnecessary to the outside world. Abstraction is about to show only essential details and [functionality](https://www.mindstick.com/interview/547/explain-about-the-functionality-of-vb-script) to the user. It provides hiding the [implementation](https://yourviews.mindstick.com/view/60537/nationalwide-nrc-implementation-bjp-looting-congress-s-idea) from the user. when we are hiding the details use private [access modifier](https://www.mindstick.com/forum/33638/protected-access-modifier-c-sharp).

**[Abstract Class](https://www.mindstick.com/blog/665/constructor-in-abstract-class-in-c-sharp) :-**

A class which contains any abstract members in it is [known as](https://answers.mindstick.com/qa/31993/who-is-popularly-known-as-iron-man-of-india) abstract class.

An abstract class is a partially implemented class used for developing some of the [operations](https://answers.mindstick.com/qa/34054/who-has-taken-charge-as-the-new-director-general-of-military-operations-dgmo-of-the-indian-army) of an object which are common for all next level subclasses.

For ex :- Rectangle, Circle, Triangle and cone.

Entities:

Rectangle : Width, Height

Circle : Radius, Pi

Triangle : Width, Height

Cone : Radius, height, Pi

Common [Attributes](https://www.mindstick.com/interview/34453/what-are-attributes-in-dot-net) :

Width, Height, radius, Pi

**[Abstract Method](https://www.mindstick.com/articles/23305/abstract-methods-and-class-in-c-sharp) :-**

1. A method does not have a body is called an abstract method. A method have abstract access modifier.

2. Overriding an abstract method is compulsory.

**For example :-**

public abstract class Figure

{

public double Width, Height, Radius;

public const float pi= 3.14f;

public abstract double GetArea();

}

public class Rectangle : Figure

{

public Rectangle(double width, double height)

{

this.Width = width;

this.Height = height;

}

public override double GetArea()

{

return Height * Width;

}

}

public class Circle : Figure

{

public Circle(double Radius)

{

this.Radius = Radius;

}

public override double GetArea()

{

return Radius*pi*pi;

}

}

public class Triangle : Figure

{

public Triangle(double Width,double Height)

{

this.Width = Width;

this.Height = Height;

}

public override double GetArea()

{

return (Width * Height) / 2;

}

}

public class Cone : Figure

{

public Cone(double Radius, double Height)

{

this.Radius = Radius;

this.Height = Height;

}

public override double GetArea()

{

return pi*Radius * (Radius+Math.Sqrt(Height*Height+Radius*Radius));

}

}

class Program

{

[static void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) Main(string[] args)

{

Rectangle rc = new Rectangle(5.62, 6.77); \

Circle cr = new Circle(5.62);

Triangle tr = new Triangle(8.62, 8.77);

Cone cn = new Cone(2.62, 4.77);

\

Console.WriteLine('Area of Rectangle ' + rc.GetArea());

Console.WriteLine('Area of Circle ' + cr.GetArea());

Console.WriteLine('Area of Triangle ' + tr.GetArea());

Console.WriteLine('Area of Cone ' + cn.GetArea());

}

}

**Output :-**

![Abstraction in oops c#](https://www.mindstick.com/mindstickarticle/89030a6c-a4f7-437b-91c8-1a2245df9d04/images/77ff205c-f1f8-4c43-9ed1-31b06043d560.png) **\**

\

---

Original Source: https://www.mindstick.com/articles/326534/abstraction-in-oops-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
