Constructors Theory Notes
Constructors
- Without constructors, objects cannot be created.
- Same as class name
- Constructor is a function which has the same name as the class and has no return value, not even void
- use- to initialize the data members/instance variables
- Types: Non-Parameterised
Parameterised
- Constructors no return type, but functions have
Default Constructor
non-parameterised
initializes variables with default values
works in absence of any user-defined constructor
Constructor Overloading
using multiple constructors in the same class with different number of arguments or type of arguments
Difference b/w Constructor and Function
- Constructor same name as class, but function has to have diff. name
- Constructor called automatically at time of object creation, function has to be called
- Constructor never returns a value, function does return or at least void
Comments
Post a Comment