What is Inheritance?

Posted by in OOPS category on for Beginner level | Views : 12894 red flag

This article will explain you about inheritance by using a suitable example for the fresher's and for the working guy's to clear the OOP's concept.

 Download source code for What is Inheritance?


This article will explain you about inheritance by using a suitable example for the fresher's and for the working guy's to clear the OOP's concept. Watch our 500 videos on Azure, WCF, WPF, LINQ, Design Patterns, WWF, Silverlight, UML @ http://www.questpond.com

What is Inheritance?

Inheritance, together with encapsulation and polymorphism, is one of the three primary characteristics (concept) of object-oriented programming Inheritance enables you to create new classes that reuse, extend, and modify the behavior that is defined in other classes The Class whose methods and variables are defined is called super class or base class The Class that inherits methods and variables are defined is called sub class or derived class Sometimes base class known as generalized class and derived class known as specialized class Keyword to declare inheritance is “:” (colon) in visual c#.

Benefits of using Inheritance

Once a behavior (method) or property is defined in a super class(base class),that behavior or property is automatically inherited by all subclasses (derived class). Code reusability increased through inheritance Inheritance provide a clear model structure which is easy to understand without much complexity Using inheritance, classes become grouped together in a hierarchical tree structure Code are easy to manage and divided into parent and child classes

Example of Inheritance

Types of Inheritance in C#: -

  • Implementation Inheritance
  • Multiple Inheritances (Interface Inheritance)

Implementation Inheritance

One base class (super class) and one derived class (sub class).

Sample Picture:


Interface Inheritance

An interface looks like a class, but has no implementation. It contains definitions of events, indexers, methods and properties. An interface inherited by classes An interface inheritance defined with keyword “interface”. In C# Interface Inheritance also known as multiple inheritances.

Inheritance Tree Structure:


Code Example

"Implementation inheritance code example" and "Interface inheritance code example" attached at the top of this article.

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Gurunatha Dogi
Member Level: Starter
Member Status: Member
Member Since: 8/13/2009 12:50:13 AM
Country: India
Gurunatha Dogi
Gurunatha Dogi, is a software engineer by education and profession. He likes c#, java, php, , asp.net, sql server and seo optimization. During free time he likes to write blogs on various technical topics and tips and tricks on search engine optimization. He likes to play guitar and cricket. Currently he is working in @Questpond one well known of e-learning firm in India.

Login to vote for this post.

Comments or Responses

Posted by: Chiragkanzariya on: 11/22/2012 | Points: 25
Nice Article

You can also check Basic concept of OOP herehttp://chiragkanzariya.blogspot.in/2012/11/oops-concept-with-real-world-example.html

Login to post response

Comment using Facebook(Author doesn't get notification)