Can we have a private virtual method ?
Answer Posted / ganesh mishra
yes... we can have private virtual method and will not give
any compile time/runtime error.but when we derive any class
from it and override the virtual function,then the compiler
will throw a compile time error.
//file name is privatever.cpp
#include <iostream>
using namespace std;
class base
{
virtual void fun()
{
cout <<"base class function"<<endl;
}
};
class derive: public base
{
public:
virtual void fun()
{
cout<<"derived class function"<<endl;
}
};
int main()
{
base *pt;
derive *der = new derive;
pt = der;
pt->fun();
return(0);
}
here is the error
privatever.cpp: In function ‘int main()’:
privatever.cpp:6: error: ‘virtual void base::fun()’ is private
privatever.cpp:27: error: within this context
Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
Write A Program to find the ambiguities in Multiple Inheritance? How are they resolved.(Virtual Functions)
What are the three parts of a simple empty class?
What does it mean when someone says I oop?
What is the point of oop?
How is polymorphism achieved?
What do you mean by Encapsulation?
There are two base class B1,B2 and there is one class D which is derived from both classes, Explain the flow of calling constructors and destructors when an object of derived class is instantiated.
What is encapsulation in oops?
What is the types of inheritance?
What is encapsulation in oop?
What is oops concept with example?
Why do we use class?
What polymorphism means?
What is the difference between procedural programming and oops?
How do you define social class?