0

Does default constructor gets called if a class with no data members in it, and why?

as we know constructor is used to initialize the instance variables.

14th May 2017, 8:15 AM
.com
.com - avatar
3 Respuestas
+ 2
You can do other things in a constructor, not just initializing members. For example you can log something.
14th May 2017, 9:14 AM
Tamás Barta
Tamás Barta - avatar
+ 1
yes the default constructor is called whenever you create an object of class.
14th May 2017, 8:40 AM
MR Programmer
MR Programmer - avatar
0
@MR Programmer the default constructor is called, whenever an object of a class is instantiated and no other constructor is called (e.g. copy constructor or a constructor with argumentd). It is even possible that a class doesn't have a default constructor (you need to declare but are not allowed to implement it). In this caseyou have to use another constructor.
14th May 2017, 10:39 AM
Volker Milbrandt
Volker Milbrandt - avatar