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.
3 Respuestas
+ 2
You can do other things in a constructor, not just initializing members. For example you can log something.
+ 1
yes the default constructor is called whenever you create an object of class.
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.