P
Pravin
Hi all,
please look at this code
"
class VirtualBase{
public:
virtual int method1() = 0;
virtual int method2()=0;
virtual int method3()=0
};
class DerivedBaseublic VirtualBase
{
public:
int method1(){
return 2;
}
int method2(){
return 2;
}
private:
int method3(){
return 2;
}
};
void main(){
DerivedBase ObjDerivedBase;
VirtualBase *ObjVirtualBase;
ObjVirtualBase = new DerivedBase;
cout<<"\nReturn:"<<ObjVirtualBase->method3();
}
"
Here..inspite of DerivedBase::method3() being private, i can still
call it using a pointer to VirtualBase after assigning a object of
DerivedBase.
I have difficulty understanding how this could be possible?
please look at this code
"
class VirtualBase{
public:
virtual int method1() = 0;
virtual int method2()=0;
virtual int method3()=0
};
class DerivedBaseublic VirtualBase
{
public:
int method1(){
return 2;
}
int method2(){
return 2;
}
private:
int method3(){
return 2;
}
};
void main(){
DerivedBase ObjDerivedBase;
VirtualBase *ObjVirtualBase;
ObjVirtualBase = new DerivedBase;
cout<<"\nReturn:"<<ObjVirtualBase->method3();
}
"
Here..inspite of DerivedBase::method3() being private, i can still
call it using a pointer to VirtualBase after assigning a object of
DerivedBase.
I have difficulty understanding how this could be possible?