Answer to Question #190039 in C++ for jainab

Question #190039

Explain with an example why constructor is important.


1
Expert's answer
2021-05-09T05:38:39-0400

The constructor is the initialization point of the any newly created object. It is a kind of member function, which will be executed at the same moment when any new object of any class has been created.

It is has the exactly same name as class object. It does not have any return type. It plays important role in the initial values for certain member variable function.

Class Student{
public:
  void studentDetails(){}
//default constructor
  Student(){}
//parametrized constructor
  Student(string name, string roll_number){
this->name=name;
this->roll_number=roll_number;
}
  
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS