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
What is encapsulation in oop?
I have One image (means a group photo ) how to split the faces only from the image?............ please send the answer nagadurgaraju@gmail.com thanks in advace...
What is a superclass in oop?
Which method cannot be overridden?
Write a c++ program to display pass and fail for three student using static member function
What do you mean by variable?
What is balance factor?
Prepare me a program for the animation of train
Can you explain polymorphism?
What is polymorphism give a real life example?
What is the problem with multiple inheritance?
What does it mean when someone says I oop?
2. Give the different notations for the class.\
What is difference between pop and oop?
How to hide the base class functionality in Inheritance?