C++ Programming - OOPS Concepts - Discussion
Discussion Forum : OOPS Concepts - General Questions (Q.No. 27)
27.
Which of the following cannot be used with the keyword virtual?
Discussion:
20 comments Page 1 of 2.
Arnab Pratihar said:
4 weeks ago
The "virtual" keyword is used to prevent early binding which checks which function is called at runtime, known as "late binding".
But the constructor is called at runtime, that's why no late binding problem occurs with the constructor. That is the actual reason virtual keyword is not used or can't be used before the constructor.
But the constructor is called at runtime, that's why no late binding problem occurs with the constructor. That is the actual reason virtual keyword is not used or can't be used before the constructor.
Rabz said:
5 years ago
Constructor cannot be virtual because the time when constructor is called, there is no virtual table in the memory yet. But destructor can be virtual.
(2)
Nitin said:
8 years ago
The virtual not work with destructor.
Pankaj said:
9 years ago
Constructors can be virtual and static. So right answer is destructor D option.
Gelu Menumorut said:
9 years ago
There is no such a thing as a "virtual class", but only the expression "virtual base class" that is just an euphemism that has sense only in the context of inheritance, meaning the base class involved in virtual inheritance, here the word "virtual" is actually an attribute of the inheritance not of the class. Is like "C++ slang", but altering the expression and it's context and making it official by saying it's a correct answer is weird, to say the least.
(1)
Prakash kuthi said:
9 years ago
Hi, it was helpful thanks to all.
Sumit said:
1 decade ago
You are thinking well. But, we can create virtual destructor.
Prosenjit Santra said:
1 decade ago
I think we cannot create virtual constructor as well as virtual destructor.
Pooja Singh said:
1 decade ago
Yes, we can declare class as a virtual. It removes ambiguity of same function name used in different classes.
Example - hybrid inheritance.
Example - hybrid inheritance.
Rajendra said:
1 decade ago
Can we declare virtual class?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers