Sunday, 30 April 2017

Difference between Initialization and Instantiation

Initialization

Initialization means assigning initial value to variables while declaring.

Example of Initialization

Following is the simple example of initialization in application.


  int a;//Declaration

  a = 10;//Initialization

  or

  int a = 10;

Instantiation

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

Example

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.