Can we have a private virtual method ?
Answer Posted / sriram
We can have the private virtual method. But it can be
accessed only through the derived class not through the
base class.
class A
{
private:
virtual void fun() { std::cout << "A::fun" <<
std::endl; }
};
class B : public A
{
public:
virtual void fun() { std::cout << "B::fun" <<
std::endl; }
};
int main(int argc, char* argv[])
{
A* pa = new A();
((B*)(pa))->fun();
}
Output : A::fun
| Is This Answer Correct ? | 4 Yes | 3 No |
Post New Answer View All Answers
How does polymorphism work?
What is the difference between a mixin and inheritance?
to find out the minimum of two integer number of two different classes using friend function
What is polymorphism and its types?
INSTANCE FIELDS DECLARED private ARE ACCESSIBLE BY THE METHODS ONLY.CAN WE CHANGE THE private FIELD OF AN OBJECT IN A METHOD OF SOME OTHER OBJECT OF THE SAME CLASS?
hi, this is raju,iam studying b.tech 2nd year,iam want know about group1 and group2 details, and we can studying without going to any instutions? please help me.
What is destructor give example?
Why is polymorphism needed?
What is persistence in oop?
What is polymorphism what are the different types of polymorphism?
How do you achieve polymorphism?
can we make game by using c
What is encapsulation with real life example?
What is the real time example of inheritance?
Is enum a class?