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


Please Help Members By Posting Answers For Below Questions

What is the example of polymorphism?

562


What is polymorphism in oops?

563


What does and I oop mean?

620


what is graphics

2013


What is the difference between abstraction and polymorphism?

619






Why do we use polymorphism?

582


What is the types of inheritance?

604


Why polymorphism is used in oops?

586


What are the features of oop?

641


what are the different types of qualifier in java?

1847


What is a null tree?

632


Can a varargs method be overloaded?

619


hi all..i want to know oops concepts clearly can any1 explain??

1683


What is variable example?

599


Write a program to sort the number with different sorts in one program ??

1923