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 are the realtime excercises in C++?
What is a class oop?
How do you define social class?
What is oops and its features?
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).
What language is oop?
Why is static class not inherited?
What are the features of oop?
What is the renewal class?
What does and I oop mean?
design a c++ class for the chess board,provide a c++ class definition for such class(only class definition is required)
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?
can inline function declare in private part of class?
What is difference between class and object with example?
What is for loop and its syntax?