A constructor is a special type of member function that is called automatically when an object is created . In C++, a constructor has the same name as that of the class and it does not have a return type. For example, class Wall { public: // create a constructor Wall() { // code } };
Read moreWhat is the constructor in Java?
A constructor in Java is a special method that is used to initialize objects . The constructor is called when an object of a class is created.
Read more