Saved Bookmarks
| 1. |
What are advantages of declaring constructors and destructor under public accessability? |
|
Answer» When constructor and destructor are declared under public: 1. we can initialize the object while declaring it. 2. we can explicitly call the constructor. 3. we can overload constructor and therefore use multiple constructors to initialize objects automatically. 4. we can destroy the objects at the end of class scope automatically (free unused memory). However, some C++ compiler and Dev C++ do not allow to declare constructor and destructor under private section. So it is better to declare constructor and destructor under public section only. |
|