Discussion
In C++, which function has the same name as the class and is called automatically when an object is created ?
Answer: C
The function is the constructor.
A C++ constructor has the same name as its class, has no return type, and is called automatically whenever an object of the class is created, to initialise its data members. A class may have several constructors with different parameters.
The destructor also takes the class name, but with a tilde (~ClassName), and it runs when an object is destroyed, not created. main is the program's entry point, and a virtual function is one that can be overridden in a derived class.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development