C++ Programming - Constructors and Destructors - Discussion
Discussion Forum : Constructors and Destructors - General Questions (Q.No. 18)
18.
Which of the following cannot be declared as virtual?
Discussion:
20 comments Page 1 of 2.
Jpb said:
2 years ago
In C++, constructors cannot be declared as virtual. Virtual functions are used for dynamic dispatch and polymorphism, but constructors are called at the time of object creation and are not inherited like other member functions. Therefore, constructors cannot be virtual.
So, the correct answer is Constructor.
So, the correct answer is Constructor.
Vedi G said:
6 years ago
All ways constructor can not be virtual, but we can apply destructor as a virtual.
It shows the wrong answer.
It shows the wrong answer.
Shubham solanki said:
6 years ago
Destructors can be virtual.
Aryan said:
6 years ago
I don't think that data members must also need to be non-virtual. Right?
Sai Ajay said:
7 years ago
Destructors can be virtual.
If I'm wrong, please correct me with right explanation.
If I'm wrong, please correct me with right explanation.
Tushar Wagh said:
8 years ago
I Agree that constructor can't be virtual but destructures can be virtual.
Virtual distructor is used to call the base class destructor in reverse order of herachiy of classes.
Virtual distructor is used to call the base class destructor in reverse order of herachiy of classes.
Prasanthreddy said:
9 years ago
The virtual constructor is not possible because the constructor is called when an object creates but virtual is possible only after object creation so, virtual constructor not possible but the virtual destructor is possible.
Laxmareddy said:
1 decade ago
Both can be declared as virtual. There is no limitation to declare only destructor as virtual.
Afroz said:
1 decade ago
How can you say destructor declare as a virtual?
Wangchuk said:
1 decade ago
How you can say that destructor cannot be declare as virtual. In the some text book I have found that destructor can be declare as virtual.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers