in the above code i created 2 classes for which i'll call main function
this gives basic idea of what is a constructor and how it works
TYPES OF CONSTRUCTORS:
- Default/ Non parameterized:
this is non parameterized constructor, which would be called whenever an object is created.
In this we'll have to declare its attributes seperately everytime like shown in the main function above.
- Parameterized:
this is parameterized constructor where its attributes are mentioned as parameters to be passed whenever creating an object. So its object creation would look as follows:
3.** Copy: **
copy constructor is used to create an object which would be copy of an already existing object. Its syntax is given above and its usage in main class is given as
Top comments (0)