What Is a constructor?
constructor in java is a special member method that will be called implicitly(automatically) by the JVM whenever an object is created for placing user or programmer-defined values in the place of default values.
The purpose of a constructor is to initialize an object called an object initialization.
Advantage of constructor
A constructor elimination placing the default values
A constructor eliminates calling the normal or ordinary method implicitly.
Properties of a constructor
constructor name must be similar to the name of the class
the constructor will be inserted when the object is created
constructor has no return even void
the constructor should not be declared static
the constructor will not be inherited
the constructor must be declared as private
the constructor may be overloaded but cannot be overriding
Type of constructor
1 Default constructor
a) system defined
b) user defined
2 parameterised
a) overloading constructor
b) copy constructor
3 private constructor
parameterized constructor
Difference between method and constructor
0 Comments