Constructor in java:
>A constructor is a special member method which will be called by the jvm automatically(implicitly) whenever an object is created for placing placing our own values instead of placing default values.
PURPOSE:
*the purpose of constructor concept is initialize an object.
*Advantages of constructor:
1.constructor Eliminates default values.
2.constructor eliminates in calling the ordinary method explicitly.
*Rules/properties of constructor:
1.constructor will be called automatically by the jvm whenever an object is created.
2.the name of constructor must be similar to class name.
3.constructor should not return an return type,even void also.(if we write any return type then it will be treated as ordinary method).
4.constructor modifier should not be static because constructor will be called each and every time whenever an object is created .java does not contain static constructors.
5.constructor will not be participated in inheritance process.bcoz every class is meant for initialization it's own object but not for initializing object of other class.
6.the acess specifier of the constructor may or may not be private.
**Types of constructor In Java:
1.Default constructor
2.Parameterised constructor
>A constructor is a special member method which will be called by the jvm automatically(implicitly) whenever an object is created for placing placing our own values instead of placing default values.
PURPOSE:
*the purpose of constructor concept is initialize an object.
*Advantages of constructor:
1.constructor Eliminates default values.
2.constructor eliminates in calling the ordinary method explicitly.
*Rules/properties of constructor:
1.constructor will be called automatically by the jvm whenever an object is created.
2.the name of constructor must be similar to class name.
3.constructor should not return an return type,even void also.(if we write any return type then it will be treated as ordinary method).
4.constructor modifier should not be static because constructor will be called each and every time whenever an object is created .java does not contain static constructors.
5.constructor will not be participated in inheritance process.bcoz every class is meant for initialization it's own object but not for initializing object of other class.
6.the acess specifier of the constructor may or may not be private.
**Types of constructor In Java:
1.Default constructor
2.Parameterised constructor
Comments
Post a Comment