Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - Difference between Instantiation and Inheriting (Inheritance) a Class

May 12, 2016
Introduction:

Here I will explain difference between instantiation and inheriting (inheritance) a class in c#, vb.net with example or instantiation vs inheritance in asp.net or how to instantiate and inherit a class in asp.net using c#, vb.net with example. In c# or vb.net instantiation means declaring object for class and inheritance means acquiring properties from base class.

Description:


Inheritance

Inheritance means it’s a kind of relation between two classes like parent and child. In inheritance child class will acquire all properties from parent class like methods, events, nested types of parent class, operators and fields.

Example of using Inheritance

Following is the simple example of defining inheritance in classes.


// Parent Class
class parent {
// your code
};
// Child Class
class child : parent {
// child class will inherit all properties from parent class
}
Instantiation

Instantiation means defining or creating new object for class to access all properties like methods, operators, fields, etc. from class.

Example if Instantiation

Following is the example of defining instantiation in application.


class sampleclass {
// your code
}
class Program
{
static void Main()
{
// Instantiating sampleclass
sampleclass sobj = new sampleclass();
}
}

If you observe above syntax we created new object by instantiating sampleclass class. By using new object sobj we can access all the methods and properties from sampleclass class.

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

1 comments :

DGanapathi said...

Hi Suresh,

You have given definitions for instantiation and inheritance, using both ways can access all properties. What is the exact difference?

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.