Preview

Constructor vs. Destructor

Powerful Essays
Open Document
Open Document
550 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Constructor vs. Destructor
Constructor Vs. Destructor

Constructor:- Constructor is like a method which may contain some certain set of statement, But constructor does not have any Return Type and it will have the same name as the Class Name.
A Constructor is called automatically when object of class created.Basically constructor is used to Initialize the data member of class.We can use constructor overloading also in the program.
• In case of parent child relationship ,when we make the object of child class, then child class constructor is called and base class default constructor is executed.

Type of Constructors:- There are some type of constructor which are use in our program.

1. Static Constructor:- Static member are those which is not changeable over whole program. Static Constructor is called automatically by CLR when class is loaded in first time in memory,before any object of class is created.
2. Non Static Constructor:- Non static member are those member which is dynamically changes over the program. Non Static constructor(Instinct Constructor) is called whenever object of the class is created. 3. Private Constructor:- In many situation, we may wish to define some utility classes that contain only static member such classes are never required to instantiate objects.Creating objects using such classes may be prevented by adding private constructor to the class. 4. Copy Constructor:- A copy constructor creates an object by copying variables from another object. Since C# does not provided a copy constructor ,we must provide it ourselves if we wish to add this feature to the class.

Constructor Overloading:- Constructor overloading is like method overloading , In this we have used same name but different signature of the Constructor. we have already discussed about signature in our previous post. This is called constructor overloading. Constructor overloading is used when object are required to perform similar task but using different input parameters.

You May Also Find These Documents Helpful

Related Topics