I am new to OOPS and was learning about virtual function that it is useful to achieve run-time polymorphism.
But I have some doubt.
#include<bits/stdc++.h>
using namespace std;
class A
{
public:
virtual void print()
{
cout<<"Inside base class private"<<endl;
}
};
class B: public A
{
private:
void print()
{
cout<<"Inside derived class private"<<endl;
}
};
int main()
{
A *ptr = new B();
ptr->print();
//ptr->show();
return 0;
}
Since in derived class our print function is private and then also it is giving output as Inside derived class private. Why it is so? It is in private section so it should have given compiler error but it is giving correct output?