Constructor



  • A constructor is a member method of a class which is invoked automatically when an object to the class is created
  • A constructor name should be same as class name
  • A constructor does not have any return type even void also
  • A constructor is used to keep something ready for the object when it is created
  • A constructor is used to initialize require values into the data fields of the class or to pass the required value into the data fields or to make required value in establishing connection to database, keeping the file open to perform some operation etc, when an object is created

    Types of Constructor:-
Instance Constructors
  • Instance Constructor will maintain separate instance for each member object of the class, for each object of the class
Non Instance Constructors
  • Non Instance Constructor will not maintain separate instances for each data field of the class for each object of the class



No comments:

Post a Comment