#include<iostream>
using namespace std;
class A
{
private:
int a,b;
public:
void setdata(int x,int y){
a=x;b=y;
}
void show_data(){
cout<<a<<b;
}
};
class B: public A{
};
main(){
B b1;
b1.setdata(3,4);
b1.show_data();
}
How does setdata work even if we don't create an object of class A (how did the variables a and b get memory)? And how was it possible to access the private variables of A using an object b1 of class B? I am surprised to see my program working properly.