I was faced this question while one of recent interview :
class1
{
virtual getname();
{//code here..}
}
class2:class1
{
overrides getname();
{//code here..}
}
class3:class2
{
public new getname();
{//code here..}
}
class4
{
class1 obj=new class3();
obj.getname();
}
now in class4 which class’s method will call ? why ? and what is call this concept in oops ?
The
getnameinclass3will be the only one that’s invoked.It’s called Method Hiding
Excerpt from link