---
title: "Inheritance in C#"  
description: "Inheritance means parent class property access child class like methods, members etc, and also reused code."  
author: "Anonymous User"  
published: 2016-05-05  
updated: 2019-11-27  
canonical: https://www.mindstick.com/articles/12037/inheritance-in-c-sharp  
category: "c#"  
tags: ["c#", "oops", "inheritance"]  
reading_time: 2 minutes  

---

# Inheritance in C#

[Inheritance](https://www.mindstick.com/articles/80/inheritance-in-c-sharp) means [parent](https://www.mindstick.com/blog/154/how-to-find-parent-of-control-in-wpf) class [property](https://www.mindstick.com/articles/198559/an-ownership-of-property-in-hua-hin) access [child class](https://www.mindstick.com/forum/159389/how-to-remove-child-class-from-active-div) like [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best), members etc, and also reused code, reason for using Inheritance is desirable because we can avoid [writing](https://www.mindstick.com/articles/13146/6-great-tools-that-will-make-your-writing-shine) code over and over again.

Any class can inherit more than one class or [interface](https://www.mindstick.com/articles/12036/interface-in-c-sharp), that means we can inherit data and [functions](https://www.mindstick.com/forum/34086/jquery-callback-functions) from [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) base classes and interfaces.

**For example****:**

**Shape class** \

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace OoopsConcepts{    class Shape    {        protected int width;        protected int height;                public void setWidth(int w)        {            width = w;        }        public void setHieght(int h)        {            height = h;        }            }}
```

Create a another class Rectangle and inherit to shape class.

**Rectangle class**\

```
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace OoopsConcepts{    class Rectangle:Shape    {        public int getArea()        {            return (width * height);        }        public int getPerimeter()        {            return 2*(width + height);        }            }}
```

And create [entry point](https://www.mindstick.com/interview/675/what-is-the-entry-point-for-window-based-application) class(RectangleTest) create object of the rectangle class call the method----

**RectangleTest class**

```
using System;                                               using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; namespace OoopsConcepts{    class RectangleTest    {        static void Main(string[]args)        {            // Inhertance Test                       Rectangle rectange = new Rectangle();            // Console.Write("")            rectangle.setWidth(10);            rectangle.setHieght(5);            Console.WriteLine("Total area : {0}", rectangle.getArea());            Console.WriteLine("Perimeter : {0}", rectangle.getPerimeter());            Console.ReadLine();        }    }}
```

---

Original Source: https://www.mindstick.com/articles/12037/inheritance-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
