Defination:-
>>Constructor is a special method or special member of the class which is used to Initialize Datamember's or Variables.
Rules
>>Constructor Name should be Same as Class Name.
>>Constructor will not have any return type.
>>Constructor will not return any value.
>>Constructor is always Non-Static.
>>Whenever an object is created Constructor will get invoked(if Instance initialization Block is declared or initialized then first IIb will get excuted and then constructor.)
Syntax | Example |
---|---|
class class_name { class_name() _________ _________ _________ return; } |
class Sample { Sample() _________ _________ _________ return; } |
Constructor are of Two Types
>>1.User-Defined Constructor.
Non-Parameterized and Parameterized
>>2.Default Constructor.