Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Why constructor is used in a class?
Posted
Updated 28-Feb-12 0:56am
v2
Comments
Rajeev Jayaram 28-Feb-12 6:57am    
[Edit] - Typo fixed.

You need to understand why a constructor is used in object-oriented programming in the first place.

A constructor is nothing but a method.
The whole idea is to prepare a new object for use (e.g. with parameters etc that the object methods might need).

A constructor can be inherited in a sub-class.
 
Share this answer
 
v3
Constructor creates the new object for using in a program. It can also be for initializing data members. It does not have any return type.
 
Share this answer
 
Refer to this nicely written CP article, An Intro to Constructors in C#[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900