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:
In
previous posts I explained @@IDENTITY vs SCOPE_IDENTITY () vs IDENT_CURRENT, difference between dispose and finalize method in c#, authorization in asp.net, difference between page_init and
page_load events in asp.net, difference between ref and out
parameters in c#, delegates in c# with example and many articles
relating to
interview questions, asp.net, c#.net. Now I will explain difference
between instantiation and inheritance in c#, vb.net with example.
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 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. |
|||
|
|||
1 comments :
Hi Suresh,
You have given definitions for instantiation and inheritance, using both ways can access all properties. What is the exact difference?
Note: Only a member of this blog may post a comment.