what is constuctor
Title
Question
what is constructor and explain.
Advanced-Cpp Constructor-And-Destructor 00-01 min 10-20 sec
Answers:
A constructor in Java is a block of code similar to a method that's called when an instance of an object is created. Here are the key differences between a constructor and a method: A constructor doesn't have a return type. The name of the constructo must be the same as the name of the class.
A constructor in Java is a block of code similar to a method that's called when an instance of an object is created. Here are the key differences between a constructor and a method: A constructordoesn't have a return type. The name of the constructo must be the same as the name of the class.
<ul style="box-sizing: inherit; -webkit-tap-highlight-color: transparent; margin-right: 0px; margin-bottom: 1.618em; margin-left: 4rem; padding: 0px; color: rgb(77, 89, 104); line-height: 2; font-family: "Nunito Sans", -apple-system, blinkmacsystemfont, "Segoe UI", roboto, helvetica, arial, sans-serif; font-size: 18px; background-color: rgb(255, 255, 255);"><li style="box-sizing: inherit; -webkit-tap-highlight-color: transparent; list-style-type: disc; line-height: 2;">It is a special method that holds the same name as the class name and initializes the object whenever it is created. So it is simple and easy to execute.</li><li style="box-sizing: inherit; -webkit-tap-highlight-color: transparent; list-style-type: disc; line-height: 2;">It is mainly used for memory management. They are used to initialize and remove memory block when it is no longer required by having New and Delete options as specified by the programmer</li></ul>
A constructor is a special type of member function of a class which initializes objects of a class. In C++, Constructor is automatically called when object(instance of class) create. It is special member function of the class because it does not have any return type.
Login to add comment