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 is constructor in oop?
String = "C++ is an object oriented programming language.An imp feature of oops is classes and objects".Write a pgm to count the repeated words from this scenario?
What is polymorphism explain its types?
State what is encapsulation and friend function?
What is polymorphism give a real life example?
What are the 5 oop principles?
What is the main purpose of inheritance law?
What is the difference between inheritance and polymorphism?
Who invented oop?
What are the two different types of polymorphism?
Why do while loop is used?
How can you overcome the diamond problem in inheritance?
given a set based questions and 5 questions based on it next data sufficiciency questions 2 and 2/3 english sentence completion with options very easy and 2 synononmys paragraph with 10 questions 10 minutes replace =,-,*,% with -,%,+,* type questions 5 3 questions lik following itssickhere itssickthere itssickhere istsickhere which is nt alike the others very easy
What are functions in oop?
Whats oop mean?