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 are the realtime excercises in C++?

2333


What is a class oop?

592


How do you define social class?

600


What is oops and its features?

585


assume the program must insert 4 elements from the key board and then do the following programs.sequential search(search one of the elements),using insertion sort(sort the element) and using selection sort(sort the element).

1662






What language is oop?

591


Why is static class not inherited?

593


What are the features of oop?

635


What is the renewal class?

2162


What does and I oop mean?

614


design a c++ class for the chess board,provide a c++ class definition for such class(only class definition is required)

6146


IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?

1577


can inline function declare in private part of class?

3657


What is difference between class and object with example?

562


What is for loop and its syntax?

596