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 solid in oops?
What is polymorphism explain?
What is for loop and its syntax?
What are oops functions?
How do you achieve polymorphism?
Following are the class specifications: class {int a}; class {int b}; Using friend funtion,calculate the max of two objects and display it.
How many human genes are polymorphic?
write a program to find 2 power of a 5digit number with out using big int and exponent ?
#include
why reinterpret cast is considered dangerous?
Write a java applet that computes and displays the squares of values between 25 and 1 inclusive and displays them in a TextArea box
What is the real time example of inheritance?
What exactly is polymorphism?
What is encapsulation selenium?
Can destructor be overloaded?