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 string class as your own class in java without using any built-in function
What are the benefits of oop?
Get me a number puzzle game-program
What is the difference between static polymorphism and dynamic polymorphism?
What is this pointer in oop?
What is destructor example?
Explain the advantages of inheritance.
Which is better struts or spring?
What is solid in oops?
#include
what type of question are asked in thoughtworks pair programming round ?
Is data hiding and abstraction same?
Get me an image implementation program.
What is encapsulation with example?
write a C++ program for booking using constructor and destructor.